My python script is on partition D and I want to rename files in folders on partition E:
I can't move the folder/files to D, because of limited space.
path= "E:\\A"
for f in os.listdir(path):
f_name, f_ext = os.path.splitext(f)
empty, f_number, f_title = (f_name.split('_'))
f_title = f_title.strip()
if len(f_number) == 2:
f_number = '0' + f_number
f_filename = '_{}_{}{}'.format(f_number, f_title, f_ext)
file = os.path.join(path, f)
os.rename(file, f_filename)
I get the error:
[WinError 17] The system cannot move the file to a different disk drive:
I found an answer here to use shutils. So I tried:
src = os.path.join(path, f)
path2 = "E:\\A2"
dst = os.path.join(path2, f_filename)
shutil.move(src, dst)
[Errno 2] No such file or directory: "E:\A2\filename"
That's strange because I'm taking the file from A and move it to A2 with a new filename, so clearly doesn't exist on A2.