I am attempting to write a script that will take a directory as an argument then go through said directory and rename files with a given extension (in this case .jpg)
here is what I have so far:
now, when I replace the directory above with '.' and drop the script into the directory I want to affect it will do its job perfectly. However when I have the directory put into the parameter of os.listdir and attempt to run it I get the following error:
What am I doing wrong?
I am using windows atm but this script is for UNIX. (if that matters let me know) I am pretty new to scripting and python (first week ever programming) so please be descriptive if at all possible!
thanks in advance!
here is what I have so far:
Code:
import os fileDir=os.listdir("c:\\Users\\Nathan\\Desktop\\Cell Pics\\") count = 1 for fn in fileDir: if fn[-4:] == '.jpg': os.rename(fn,'%03i.jpg' % count) count += 1
Code:
Traceback (most recent call last): File "C:/Python27/test2.py", line 7, in <module> os.rename(fn,'%03i' % count) WindowsError: [Error 2] The system cannot find the file specified
I am using windows atm but this script is for UNIX. (if that matters let me know) I am pretty new to scripting and python (first week ever programming) so please be descriptive if at all possible!
thanks in advance!
Comment