Proposal for std.path replacement

Jonathan M Davis jmdavisProg at gmx.com
Sun Mar 6 01:18:34 PST 2011


On Sunday 06 March 2011 00:37:15 Rainer Schuetze wrote:
> Looks good overall. I have a few comments and nitpicks though:
>  >   basename("dir/subdir/")             -->  "subdir"
>  >   directory("dir/subdir/")      -->  "dir"
> 
> Is this what everybody expects? I'm not sure, but another possibility
> would be to treat these as if "dir/subdir/." is passed. What is the
> result of directory("/") or directory("d:/")?

How about

baseName("dir/subdir/") -->  "subdir/"
dirName("dir/subdir/")   -->  "dir"

There _are_ programs (such as rsync) which care about whether a / is included at 
the end of the path. Doing that should also deal with the "/" and "d:/" issue. 
So, I can see why Lars would have made the base name of "dir/subdir" be "subdir" 
instead of "subdir/" (I don't know whether that's the current behavior or not, 
so he may just have copied it from what's currently there), but It seems to me 
that it will be more consistent to truet "subdir/" as the base name of 
"dir/subdir". Unfortunately, sometimes there _is_ a difference between "subdir" 
and "subdir/".

>  >   extension("file")               -->  ""
>  >   extension("file.ext")           -->  "ext"
> 
> What about "file."? I tried it on NTFS, but trailing '.' seems to always
> be cut off. Is it possible to create such a file on unix systems? If
> yes, you won't be able to recreate it from the result of basename() and
> extension().

*nix doesn't really do anything special with any file names. The closest is files 
which start with "." - most programs consider those to be hidden and don't show 
them. There's definitely no problem with using "file." as a file name. This is 
probably a good argument for putting the "." back in the extension like it was 
before.

> What about network shares like "\\server\share\dir\file"? Maybe it
> should also be shown in the examples? Does the "\\server" part need
> special consideration?

Probably, unfortunately. \\ is kind of like a drive letter, so it really should 
be special cased, I think.

- Jonathan M Davis


More information about the Digitalmars-d mailing list