File names with slashes [was Re: error in os.chdir]

eryk sun eryksun at
Sun Jul 1 22:01:27 EDT 2018

On Sun, Jul 1, 2018 at 4:30 PM, eryk sun <eryksun at> wrote:
> On Sun, Jul 1, 2018 at 8:51 AM, Steven D'Aprano
>>     spam/eggs
>> And how would that file be displayed in the Windows GUI file explorer?
> I suppose if a file system allowed forward slash in names that
> Explorer would just display it. When I get the time, I'll attach a
> debugger to explorer.exe and hack a forward slash into one of the
> names in a directory listing, i.e. a result from WinAPI FindFirstFile
> (or native NtQueryDirectoryFile).

I checked this by attaching a debugger to an instance of explorer.exe
and opening a folder that has a single file named "spam eggs.txt".
With a breakpoint on NtQueryDirectoryFile, I changed the filename to
"spam/eggs.txt" in the directory listing (an array of
FILE_ID_BOTH_DIR_INFORMATION records). As expected, Explorer just
displays the filename "spam/eggs.txt" if that's what the file system
returns from the NtQueryDirectoryFile system call. However, even if a
file system allowed such a name, it wouldn't be accessible normally.
It requires a \\?\ path, which bypasses canonicalization.

More information about the Python-list mailing list