Francisco Azocar
Francisco Azocar

Reputation: 47

WinError 17, WinError 12, and others when trying to rename files

I am trying to rename an X amount of JPG files that are in a folder with no success. The most frequent error I get is Winerror 12 and Winerror 17.

The .py file is inside the folder I want to modify the files of.

import shutil, os, re
from pathlib import Path
    
p = Path('d:\\CCACO\\CCA TEMPLATE\\C001066 Sugar Creek\\Photos FGA')
  
x = list(p.glob('*.?p?'))
y = enumerate(x, start=1)
    
for oldFileName in x:
   newFileName = 'NEW NAME'
   os.rename(oldFileName, newFileName)
   print(x)

Error: line 26, in <module>
os.rename(oldFileName, newFileName)
OSError: [WinError 17] The system cannot move the file to a different disk drive

I keep getting this error or variants and I do not know why if I am not trying to move anything.

Upvotes: 0

Views: 362

Answers (1)

Killerz0ne
Killerz0ne

Reputation: 344

your error is raised because you rename several files in the same way as said in the docs. You could add the enumerator to the new name like so:

newFileName = 'NEW NAME'+str(y)

Upvotes: 1

Related Questions