Reputation: 6531
I have a large list of file names that are illegal, I want to rename them with the 'ren
' command. How can I execute 'ren
' in batch on windows 7 with python?
Upvotes: 2
Views: 439
Reputation: 53
sts = os.system("mycmd" + " myarg")
or
sts = call("mycmd" + " myarg", shell=True)
http://docs.python.org/library/subprocess.html
example:
import os
os.system("rename.bat")
#or use command "start" for start bat files
Upvotes: 0
Reputation: 12486
Are you sure you don't really want to use a batch renaming utility?
Don't reinvent the wheel.
Upvotes: 0
Reputation: 11636
You should use the python function, it will be easier to catch errors rather than relying on the ren
command.
import os
os.rename(src, dst)
Upvotes: 2