From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=SPF_FAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 747EFBC69 for ; Fri, 20 Jul 2007 23:23:17 +0200 (CEST) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l6KLNG4r009982 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Fri, 20 Jul 2007 23:23:17 +0200 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1IBzwS-0006z9-A2 for caml-list@inria.fr; Fri, 20 Jul 2007 23:23:16 +0200 Received: from ks300734.kimsufi.com ([91.121.65.225]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 20 Jul 2007 23:23:16 +0200 Received: from gildor by ks300734.kimsufi.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 20 Jul 2007 23:23:16 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Sylvain Le Gall Subject: Re: absolute_name ? Date: Fri, 20 Jul 2007 21:23:09 +0000 (UTC) Message-ID: References: <46A0E915.1000903@univ-savoie.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: ks300734.kimsufi.com User-Agent: slrn/0.9.8.1pl2 (Debian) Sender: news X-Miltered: at concorde with ID 46A127C4.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; christophe:01 raffalli:01 christophe:01 raffalli:01 univ-savoie:01 basename:01 dirname:01 getcwd:01 chdir:01 getcwd:01 chdir:01 lib:01 le-gall:01 ocaml:01 topfind:01 On 20-07-2007, Christophe Raffalli 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