Trying to get to know the python standard library and make some of them using my Windows machine. Using python 2.7 I have the following small script that is designed to search the directory and rename all the files in it after removing the digits from the file name. I get a typeerror that says: "the string should be encoded without NULL bytes, not str"
it calls lines 5 and 18, indicated below , where im uses os.path.exists.
Any help would be greatly appreciated!
import os, re, string, glob path = os.path.normpath('C:\Users\me\Photo Projects\Project Name\Project Photos\Modified\0-PyTest') ln5:if os.path.exists(path): print "path exists at " + path for file in glob.glob(os.path.join(path, '*.jpg')): new_path = os.path.join(os.path.dirname(file), re.sub('\d', '', os.path.basename(file))) line18: if not os.path.exists(new_path): os.rename(file, new_path)
tim
source share