How does one work with filenames that end in a period in Python? According to MSDN's site, such filenames are valid in Windows, but whenever I try to create one in Python, it removes the final period. I even tried creating a raw file descriptor with os.open, but it still removes the period.
For example, this will create a file simply named 'test
'
os.open('test.', os.O_CREAT | os.O_WRONLY, 0777)
Edit: Here is the exact quote
About spaces and dots in filenames and directories. The limits are in the windows shell -- not in Windows or NT. Using 'bash', you can create files with spaces (or dots), both, at the beginning and end of a filename. You can then list and open those files in explorer, and you can 'list' them in the shell (cmd.exe), but you won't necessarily be able to open them from the shell (especially trailing spaces and dots).
Windows will strip the final trailing period, assuming it is the delimiter between a filename and a blank extension. Try using two periods.
I figured out how to do this. Apparently, passing a normal filename will strip the period even when calling the Win API directly from C. In order to create the weird filenames, you must use the
\\?\
prefix (this also disables relative paths and slash conversion).It's ugly and nonportable, but it works.
The
\\?\
syntax also works withcmd.exe
: