I started writing a python script to rename files. I wanted it to be able to rename multiple files in a given directory. I started off trying to use rename but then found other options Can't quite get it to happen.
Hope my code is understandable, can anyone assist in why it doesn't work?
""" To take input from user (directory and characters) read files in a directory and remove characters(word) from the filenames in that directory so for c:\somedirectory\lovelyname_annoying_chars.txt return c:\somedirectory\lovelyname.txt input input --> dir/name.ext""" import os # get the directory from user targetfolder = raw_input('enter a target folder:\n').strip() # get characters to remove charArgs = raw_input('What Characters to remove: ') # read all filenames in directory filenames = walk(targetfolder,names) def removechars(*names): # use os.path.splitext() function to remove file extension a = names.splitext() # split names at point where charArgs occur b = a.split(charArgs) # Rejoin new filename and extension newname = join(a, b) write newname