I have made a Python program which will clean up the unnecessary names present in my downloaded torrent files+folders, so that I can upload it to my unlimited Google Drive Storage Account without much hassle.
However, it gives me the: WindowsError: [Error 2] The system cannot find the file specified after certain number of iterations.If I run the program again, it works fine for a certain iterations and then the same error pops up.
Note that I have taken precautions using os.path.join to avoid this error but it keeps coming up. Because of this error, I have to run the program tens of times over a selected folder/drive.
Here is my program:
import os
terms = ("-LOL[ettv]" #Other terms removed
)
#print terms[0]
p = "E:\TV Series"
for (path,dir,files) in os.walk(p):
for name in terms:
for i in files:
if name in i:
print i
fn,_,sn = i.rpartition(name)
os.rename(os.path.join(path, i), os.path.join(path, fn+sn))
for i in dir:
if name in i:
print i
fn,_,sn = i.rpartition(name)
os.rename(os.path.join(path, i), os.path.join(path, fn+sn))
And the Error Traceback:
Traceback (most recent call last):
File "E:\abcd.py", line 22, in <module>
os.rename(os.path.join(path, i), os.path.join(path, fn+sn))
WindowsError: [Error 2] The system cannot find the file specified