caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Sylvain Le Gall <gildor@debian.org>
To: caml-list@inria.fr
Subject: Re: absolute_name ?
Date: Fri, 20 Jul 2007 21:23:09 +0000 (UTC)	[thread overview]
Message-ID: <slrnfa29tt.f1k.gildor@gallu.homelinux.org> (raw)
In-Reply-To: <46A0E915.1000903@univ-savoie.fr>

On 20-07-2007, Christophe Raffalli <christophe.raffalli@univ-savoie.fr> wrote:
>
> Is this the best (and only) way to get the absolute name to a file in a way that would work on all 
> system (windonws, OS X, unix, ...) ?
>
>
> let absolute_name str =
>    let base = Filename.basename str in
>    let dir = Filename.dirname str in
>    let saved_dir = Sys.getcwd () in
>    Sys.chdir dir;
>    let res = Filename.concat (Sys.getcwd ()) base in
>    Sys.chdir saved_dir;
>    res
>
> I find this a bit complicated, so I may be missing some functions in Sys, Filename or some other lib ...
>

Maybe, you can have a look at ocaml-fileutils.

http://le-gall.net/sylvain+violaine/ocaml-fileutils.html

You can use either "readlink" if you want to solve the link and the
current working dir (the file need to exist)

(you have also FileUtil.Default.make_absolute which can apply to a non
existing file)

Here is an example:

$> ocaml

# #use "topfind";;
# #require "fileutils";;
# open FilePath.DefaultPath;;
# open FileUtil.StrUtil;;
# ls ".";;
- : FileUtil.filename list =
["./ocaml_3.10.0-5.dsc"; "./ocaml_3.10.0-5.dsc.asc";
 "./ocaml-base-nox_3.10.0-5_i386.deb"; "./ocaml_3.10.0-5_i386.deb";
 "./ocaml-source_3.10.0-5_all.deb"; "./camlp4_3.10.0-5_i386.deb";
 "./camlp4-extra_3.10.0-5_i386.deb"; "./ocaml_3.10.0-5.dsc.gpg";
 "./ocaml_3.10.0.orig.tar.gz"; "./ocaml-base_3.10.0-5_i386.deb";
 "./ocaml_3.10.0-5.diff.gz"; "./ocaml-interp_3.10.0-5_i386.deb";
 "./ocaml-mode_3.10.0-5_all.deb";
"./ocaml-compiler-libs_3.10.0-5_i386.deb";
 "./ocaml-nox_3.10.0-5_i386.deb";
 "./ocaml-native-compilers_3.10.0-5_i386.deb"]
# readlink "./ocaml_3.10.0-5.dsc";;
- : FileUtil.filename =
"/home/gildor/public_html/debstage/builder/queue/ocaml/ocaml_3.10.0-5.dsc"
# make_absolute (pwd ()) "./toto";;
- : FilePath.DefaultPath.filename =
"/home/gildor/public_html/debstage/builder/queue/ocaml/toto"

DefaultPath stands for the path for the current OS. You can use
UnixPath, MacOSPath, Win32Path or CygwinPath if you want to bypass OS
detection.

The documentation is a bit complicated, i need to rewrite it at some
point in the future.

Regards,
Sylvain Le Gall


  reply	other threads:[~2007-07-20 21:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-20 16:55 Christophe Raffalli
2007-07-20 21:23 ` Sylvain Le Gall [this message]
     [not found] ` <46B1BCD1.9030004@trusted-labs.fr>
2007-08-02 14:36   ` [Caml-list] " Christophe Raffalli
2007-08-02 16:21     ` skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=slrnfa29tt.f1k.gildor@gallu.homelinux.org \
    --to=gildor@debian.org \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).