28 Minutes Ago | Add Reputation Comment | Flag Bad Post
One last problem with my script, it returns this error message...
Traceback (most recent call last): File "C:/Python26/Renamer 3", line 23, in <module> os.rename(fname, b)WindowsError: [Error 2] The system cannot find the file specified.Traceback (most recent call last): File "C:/Python26/Renamer 3", line 23, in <module> os.rename(fname, b) WindowsError: [Error 2] The system cannot find the file specified.
This is my almost completed script, feel free to use the completed version.
#!/usr/local/bin/python import re, os from os.path import join as pjoin, isdir while True: targetfolder = raw_input('enter a target folder:\n').strip() if isdir(targetfolder): break else: print("you must enter an existing folder!") newname = raw_input('enter a new base name:\n').strip() newname = pjoin(targetfolder, newname) rxin = raw_input('enter a regex to search for:\n').strip() allowed_name = re.compile(rxin).match a = 0 for fname in os.listdir(targetfolder): if allowed_name(fname): a += 1 c = os.path.splitext(fname) b = (newname + str(a) + c) os.rename(fname, b) print((fname, b))
The Print function perfectly shows the name change is possible when the os.rename line is hashed as a comment, and when i alter the variable fname in the line...
The line is making the scripts specifically search for files named "fname".
I get messages such as " the rename command only takes 2 variable... you have 3 ect, and "commands or built in fuctions cannot be used, variable one must be a string... when i attempt to alter fname to other possible variables such as rxin, ragex or oldname.
ive tried for about an hour and a half to get this last line right, but i just cant do it.
ive even tried...
os.rename(All, b) os.rename(oldname, b) os.rename((oldfname), b) os.rename(allowed_name, b)