On 2/13/22, Eric Fahlgren <ericfahlg...@gmail.com> wrote: > > That may or may not work as Windows has inconsistent treatment of multiple > separators depending on where they appear in a path. If TEMP is a drive > spec, say "t:\", then it expands to "t:\\spam.csv", which is an invalid > windows path. If TEMP is a directory spec, "c:\temp\", then it expands to > "c:\temp\\spam.csv", which works fine. > > C:\> dir c:\\temp\junk > The filename, directory name, or volume label syntax is incorrect.
"c:\\temp\junk" isn't always invalid in CMD, and definitely not in the Windows API. The problem occurs because the DIR command in the CMD shell has legacy support to ignore the drive (e.g. "C:") when the root of the path is exactly two backslashes -- because DOS in the 1980s (i.e. they went out of their to add this behavior in CMD to make it compatible with DOS). To see this, check the "C$" administrative share on "localhost": C:\>dir /b C:\\localhost\C$\Temp\spam.txt File Not Found C:\>echo spam >C:\\Temp\spam.txt C:\>dir /b C:\\localhost\C$\Temp\spam.txt spam.txt Even though using two backslashes for the root of a drive path is allowed in the Windows API itself, it's sill problematic. The path part r"\\path\to\file" can't be used as relative to the current drive of the process because it's always a UNC absolute path. So it should be normalized to r"\path\to\file" as soon as possible, e.g. via GetFullPathNameW(): >>> print(nt._getfullpathname(r'C:\\path\to\file')) C:\path\to\file _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/NAELNA54K5RDB23CM4MVGXRN7PBPNVYT/ Code of Conduct: http://python.org/psf/codeofconduct/