I am trying to make a quick Python script to rename a bunch of files. These files were made on a Linux system on this NTFS drive, but now I'm on Windows. The naming convention is as follows:
Screenshot at 2016-12-11 21:12:56.png
Symbol : is illegal in Windows file names, so the behavior of this script is a bit strange for me.
for i in os.listdir("."): print(i) x = i.replace(":", "-") comm = """mv "{}" "{}" """.format(i, x) os.system(comm)
In the above code, print(i) successfully prints the file names. 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, it seemed a little strange to me that Python under Windows can say that these naughty files exist, but cannot move them. Secondly, what is the best way to get around this?
I also tried shutil.move() and os.rename() with no luck. This question seems to be discussing this issue, but seems to care more about prevention rather than eliminating it. I obviously could go back to Linux and fix it, but I wonder if I can fix it on Windows.
source share