Behaviour of os.path.join

Roel Schroeven roel at roelschroeven.net
Wed May 27 18:39:30 EDT 2020


BlindAnagram schreef op 27/05/2020 om 22:55:
> On 27/05/2020 18:42, Roel Schroeven wrote:
>> BlindAnagram schreef op 27/05/2020 om 18:53:
>>> Its not my bug to fix - the semantics of what I send is very clear on
>>> any Windows system.
>>
>> That's the first time I see any mention of those semantics, and I've
>> been using Windows since the Windows 3.1 days (and MS-DOS before that,
>> since 3.2 IIRC).
> 
> Well I can only say that I am surpised that anyone working on Windows
> code development for as long as you have doesn't know that a path that
> ends in '\\' is a path to a directory.

A path ending in a backslash cannot refer to a file, that much is true. 
So if you have such a path and you insist that path is not an incomplete 
path, than it must out of necessity be a directory. But a path not 
ending in a backslash can refer to a directory just as well.

If those semantics are as clear as you say, it shouldn't be too 
difficult to point us to a section in the Windows documentation that 
confirms that.

A quick search turns up "Naming Files, Paths, and Namespaces" 
(https://docs.microsoft.com/nl-be/windows/win32/fileio/naming-a-file) 
which seems to be relevant. I see some example directory names without 
backslashes at the end, and I see text like

"Note that a directory is simply a file with a special attribute 
designating it as a directory, but otherwise must follow all the same 
naming rules as a regular file. Because the term directory simply refers 
to a special type of file as far as the file system is concerned, some 
reference material will use the general term file to encompass both 
concepts of directories and data files as such. Because of this, unless 
otherwise specified, any naming or usage rules or examples for a file 
should also apply to a directory."

and

"Note that directory names are stored by the file system as a special 
type of file, but naming rules for files also apply to directory names. 
To summarize, a path is simply the string representation of the 
hierarchy between all of the directories that exist for a particular 
file or directory name."

I find no hints of adding a backslash at the end to indicate directories.

If you can point me to convincing evidence in the documentation I'll 
change my mind.

I'm sorry if my language seems abrasive; that is not my intention. I'm 
only trying to help you and clear up a misunderstanding (which could be 
mine, if it turns out you're right after all).

-- 
"Honest criticism is hard to take, particularly from a relative, a
friend, an acquaintance, or a stranger."
         -- Franklin P. Jones

Roel Schroeven



More information about the Python-list mailing list