File: ziptools/ziptools/docetc/illegal-filenames-demo-1.3/py-windows-ntfs-illegal.txt

# Demo Windows 10, NTFS filesystem.
# Filesystems do not differ, and folders do not differ from files.
# This was run in Command Prompt on a Windows-10 Dell PC.

>>> import os, glob
>>> os.getcwd()
'C:\\Users\\me\\Desktop\\temp'
>>>
>>> nonport = ' \x00 / \\ | < > ? * : " '.replace(' ', '')
>>> for c in '_' + nonport + '^':
...     try:
...         name = 'temp' + c + '.txt'
...         n = open(name, 'w').write('spam')
...     except Exception as E:
...         print(name, '=>', 'FAIL', E.__class__.__name__, E)
...     else:
...         print(name, '=>', 'okay')
...
temp_.txt => okay
temp .txt => FAIL ValueError embedded null character
temp/.txt => FAIL FileNotFoundError [Errno 2] No such file or directory: 'temp/.txt'
temp\.txt => FAIL FileNotFoundError [Errno 2] No such file or directory: 'temp\\.txt'
temp|.txt => FAIL OSError [Errno 22] Invalid argument: 'temp|.txt'
temp<.txt => FAIL OSError [Errno 22] Invalid argument: 'temp<.txt'
temp>.txt => FAIL OSError [Errno 22] Invalid argument: 'temp>.txt'
temp?.txt => FAIL OSError [Errno 22] Invalid argument: 'temp?.txt'
temp*.txt => FAIL OSError [Errno 22] Invalid argument: 'temp*.txt'
temp:.txt => okay
temp".txt => FAIL OSError [Errno 22] Invalid argument: 'temp".txt'
temp^.txt => okay
>>>
>>> os.mkdir('temp|dir')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'temp|dir'
>>>
>>> glob.glob('temp*')
['temp', 'temp^.txt', 'temp_.txt']



[Home page] Books Code Blog Python Author Train Find ©M.Lutz