python - Recursively name all .pyc.py files to .py files -
i'm trying recursively rename .pyc.py
files .py
files.
my code:
import os,sys def main(): ffolder = raw_input("folder >> ") folder = 'c:\users\account name\desktop\disney\toontown\\'+ ffolder +'' filename in os.listdir(folder): infilename = os.path.join(folder,filename) if not os.path.isfile(infilename): continue oldbase = os.path.splitext(filename) newname = infilename.replace('.pyc.py', '.py') output = os.rename(infilename, newname) while true: main()
it works fine requires me type in each folder name. how make on own?
use os.walk
recursively traverse directory tree.
import os import fnmatch dirpath, dirnames, filenames in os.walk(folder): f in filenames: if f.endswith('.pyc.py'): os.rename(os.path.join(dirpath, f), os.path.join(dirpath, f[:-7] + '.py'))
Comments
Post a Comment