std.path.getName(): Screwy by design?

Nick Sabalausky a at a.a
Tue Mar 1 13:30:20 PST 2011


"Daniel Gibson" <metalcaedes at gmail.com> wrote in message 
news:ikj0cb$mbh$2 at digitalmars.com...
> Am 01.03.2011 15:31, schrieb Lars T. Kyllingstad:
>> On Tue, 01 Mar 2011 08:50:29 -0500, Nick Sabalausky wrote:
>>
>>> "Steven Schveighoffer"<schveiguy at yahoo.com>  wrote in message
>>> news:op.vrn2pooteav7ka at steve-laptop...
>>>> On Tue, 01 Mar 2011 08:13:33 -0500, Lars T. Kyllingstad
>>>> <public at kyllingen.nospamnet>  wrote:
>>>>
>>>>> On Tue, 01 Mar 2011 08:02:44 -0500, Steven Schveighoffer wrote:
>>>>>
>>>>>> On Tue, 01 Mar 2011 04:16:36 -0500, Jonathan M Davis
>>>>>> <jmdavisProg at gmx.com>  wrote:
>>>>>>
>>>>>>> I can understand if the path stuff
>>>>>>> can't deal with / or \ in file names (that's probably not worth
>>>>>>> trying to get to
>>>>>>> work right), but it _should_ be able to handle directories with dots
>>>>>>> in them and
>>>>>>> files with no extension.
>>>>>>
>>>>>> / and \ are not legal in names on any filesystem that I know of.
>>>>>>
>>>>>> -Steve
>>>>>
>>>>> On a *NIX machine, try
>>>>>
>>>>>    touch "c:\\foo\\bar"
>>>>>
>>>>> You may be surprised. ;)
>>>>
>>>> bleh... that seems useless :)  I purposely checked FAT before posting,
>>>> because I was sure Unix disallowed backslashes, I wanted to make sure
>>>> FAT didn't allow slashes.
>>>>
>>>> Holy crap, something that DOS got right and Unix didn't!
>>>
>>> Windows also handles files/paths with spaces a hell of a lot better than
>>> Unix. This, despite the fact that Unix technically allowed them long
>>> before Windows did. (I don't mean this as OS-bashing.)
>>
>> I really don't understand what you guys are talking about.  If you
>> encounter a filename with spaces, just enclose it in quotes or escape the
>> spaces.  If you encounter a filename with characters like *, \, etc, just
>> escape them or enclose the filename in single quotes.
>>
>> And you only have to do the above when using a command-line shell.  I
>> just tried renaming a file to "c:\foo bar\*.baz" using the GNOME file
>> manager and it worked perfectly, just like any other name.
>>
>>
>>>>  From this page: http://en.wikipedia.org/wiki/Filename, it appears that
>>>> really, the only disallowed character in unix filenames is '/'.  Even
>>>> '*' is allowed as a filename.  How... horrible.
>>
>> Yeah, the only illegal filename characters are '/' and null.
>>
>>
>>> I would actually feel very good to just simply not support such things.
>>> If some unix user is going to use such awful filenames they can just
>>> deal with the consequences. (And I'm *rarely* the kind of person to hold
>>> such a viewpoint on software development matters.)
>>
>> If you have a bunch of "reserved characters", that means more special
>> cases to worry about in code.  I say it's better to allow as many
>> characters as possible.
>>
>> -Lars
>
> There are some fun special cases in Windows (originating in DOS):
> http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx#naming_conventions 
> (reserved device names).
> I think even CON.txt etc (a reserved name with an extension) is illegal.
>

My interpretation of that is: Those are all under "Naming Conventions", so 
it's not so much "illegal names" as it is "names that your programs 
shouldn't allow".

Although, my interpretation might be wrong...Some interesting little 
experiments I just tried (WinXP):

- In Explorer, rename a file to "CON": Nothing happens. The filename remains 
unchanged and no message occurs. Same result with "con".

- In Explorer, rename a file to "CON.txt". Error message: "A file with the 
name you specified already exists." Same result with "con.txt".

- Some of the commandline apps I've written in D2/Phobos take an output 
filename on the comand line. Using one of them to try to create a file named 
either "CON", "CON.txt", "con", or "con.txt" results in the file's content 
being displayed to the screen (and a whole hell of a lot of beeping, since 
it's a binary file ;) ). No actual file was created as far as I could tell.

But I woudn't be surprised if there's some API other than whatever Phobos 
uses that might allow it.

In any case, score one for unix including special names like that as part of 
the filesystem.




More information about the Digitalmars-d mailing list