|
|
Choosing A Webhost: |
Re: Proposal : Path: msg#00004lang.ocaml.lib.devel
On Fri, 14 Nov 2003, Nicolas Cannasse wrote: > Hi list, > I came up very recently with a typical problem. > I had a file A and its relative path, I had a file B and its absolute path, > I wanted to get the file B path relative to A.... not so easy actually. I > wrote this small module Path : > > Path.make "my/../path/./" build a relative path > Path.absolute give the absolute path > Path.relative a b give the path of a relative to b > Path.up goes up one directory > > I did some tests under windows , it looks like it works well. If people can > test it under *nix... > > Note : this does not actually do any system checking ( the path may not > exists or contains invalid characters ). Only special paths . .. and / ( and > windows drive letters ) are recognized as special. Hi, Such a module seems very important to me too. I've got some suggestions too. It seems important to me to be able to choose input/output style: Unix, Windows, MacOS, and others. Maybe as an option passed to functions "make" and "to_string". type style = Unix | Windows | Cygwin | ... let default_style = match Sys.os_type with "Win32" -> Windows | "Unix" -> Unix | ... let of_string ?(style = default_style) s = ... let to_string ?(style = default_style) x = ... This is less clear to me, but I feel that it would be convenient to split the type t into a root part and a virtual path part: type root = Windows of string | Unix | Current_dir | Path of t and t = { root : root; virtual_path : string list } ... and implement functions that change either the root or the virtual path. Some problems concerning the current implementation under Linux: 1. //tmp///toto is valid and equivalent to /tmp/toto (because any filename must have at least one character) 2. /../../.. is equivalent to / (which is dangerous anyway) 3. toto/ is more restrictive than toto (trailing slash indicates that toto must be a directory), so don't output trailing slashes except for the root directory, or introduce a distinction between files and directories. For solving points 1 and 2, maybe it would be nice to introduce 2 input styles: Unix and Abstract, where Unix conforms to Unix (Linux?) standards and Abstract is something more abstract, that makes "/.." invalid and allows 0-length filenames (would it be useful?). Martin ------------------------------------------------------- This SF.Net email sponsored by: ApacheCon 2003, 16-19 November in Las Vegas. Learn firsthand the latest developments in Apache, PHP, Perl, XML, Java, MySQL, WebDAV, and more! http://www.apachecon.com/
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Proposal : Path, Michal Moskal |
|---|---|
| Next by Date: | Re: Proposal : Path, Yamagata Yoriyuki |
| Previous by Thread: | Re: Proposal : Path, Nicolas Cannasse |
| Next by Thread: | Re: Proposal : Path, skaller |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |