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

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -