How to create a file name with a finite period in Windows?

How to work with file names that end in Python? According to MSDN, such file names are valid on Windows, but whenever I try to create them in Python, it removes the last period. I even tried to create a raw file descriptor with os.open, but it still removes the period.

For example, this will create a file simply called ' test '

 os.open('test.', os.O_CREAT | os.O_WRONLY, 0777) 

Edit: Here is the exact quote

About spaces and periods in file names and directories. The limits in the Windows shell are not in Windows or NT. Using 'bash', you can create files with spaces (or periods), both at the beginning and at the end of the file name. Then you can view and open these files in Explorer, and you can "list" them in the shell (cmd.exe), but you do not have to be able to open them from the shell (especially for end spaces and points).

+7
source share
3 answers

I figured out how to do it. Apparently, passing a normal file name will split the period even when calling the Win API directly from C. To create strange file names, you must use the \\?\ Prefix (this also disables relative paths and slash conversion).

 open('\\\\?\\C:\\whatever\\test.','w') 

It is ugly and unbearable, but it works.

+6
source

The syntax \\?\ Also works with cmd.exe :

 dir>"\\?\C:\whatever\test." 
+4
source

Windows will split the end period, assuming it is a separator between the file name and the empty extension. Try using two periods.

0
source

All Articles