As we all know, filenames in Windows can't contain colons. However, I ran into a problem, that can be reproduced with the following sample code:
import os
os.chdir('./temp')
names = ['a', 'b', 'word1: word2', 'c: file', 'd: file']
for name in names:
with open(name, 'w') as f:
f.write('foo')
This script creates three files in the ./temp
directory: a
, b
(with 'foo') and word1
(empty). It also creates a file named file
in D:\
, which is removable storage. It doesn't create anything in C:\
, which requires administrator rights to write in; however, it does create a file in the current working directory.
I don't understand three things:
word1
file empty? On Windows systems, files and directory names cannot be created with a colon (:). But if a file or directory name is created with a colon on a Linux or Mac operating system, then moved to a Windows system, percent encoding is used to include the colon in the name in the index.
A colon is an invalid character for a Windows file name. You won't be able to allow ':' in the file name, but you can work around it.
Unfortunately, the Mac's HFS+ file system uses the COLON as a path separator just as Unix-like OSes use SOLIDUS / (slash) and Microsoft OSes use REVERSE SOLIDUS \ (backslash). All three characters must be avoided when naming a file or folder for compatibility.
Semicolons are legal in NTFS file paths. Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following: The following reserved characters: < (less than)
Windows NTFS supports file "stream". You basically append data to a file, outside of the file, and can't be viewed normally. When you created the file "word1:word2", the hidden stream "word2" is attached to "word1". If you copied the file word1 to another NTFS machine, the word2 data would come with you
Go here http://technet.microsoft.com/en-us/sysinternals/bb897440.aspx and download the streams program. Running it will show you that word2 is a stream attached to word1
This page also talks about streams: http://www.forensicfocus.com/dissecting-ntfs-hidden-streams
To really prove this easily, you can use Notepad but you need to use the .txt extension:
file=open('word1.txt:word2.txt','w')
file.write('Testing streams')
file.close()
Now, using the cmd program, change directories to where you created the files. Type the following:
c:\tmp> notepad word1.txt
You will see an empty file. Now, try this:
c:\tmp> notepad word1.txt:word2.txt
You should see the text Testing streams
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With