I'm trying to make a quick Python script to rename a bunch of files. These files were made in a Linux system on this NTFS drive, but I'm now on Windows. The naming convention looks like this:
Screenshot at 2016-12-11 21:12:56.png
The :
character is illegal in Windows filenames, so the behaviour of this script is a little strange to me.
for i in os.listdir("."):
print(i)
x = i.replace(":", "-")
comm = """mv "{}" "{}" """.format(i, x)
os.system(comm)
In the above code, the print(i)
prints the filenames happily. However when I try to run os.system(comm)
to rename my files, I get this error:
mv: cannot stat ‘Screenshot at 2016-12-24 14:54:57.png’: No such file or directory
Firstly, I find it a little strange that Python under Windows can tell that these naughty files exist, but isn't able to actually move them. Secondly, what's the best way to get around this issue?
I've also tried shutil.move()
and os.rename()
with no luck. This SO question seems to discuss the issue, but seems more concerned with prevention than fixing it. I could obviously switch back to Linux and fix it, but I'm wondering if I can't fix it on Windows.