如何在Windows中创建带有尾随句点的文件名?

2024-04-20 00:48:21 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python中,如何处理以句点结尾的文件名?根据MSDN的网站,这样的文件名在Windows中是有效的,但是每当我试图用Python创建一个文件名时,它就会删除最后一个句点。我甚至尝试用os.open创建一个原始文件描述符,但它仍然删除了句点。

例如,这将创建一个名为“test”的文件

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

编辑: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).


Tags: and文件theintestyouos文件名