The goodreader of ipad does not support JS files very well. Although it can be read, it cannot exit and the main interface of goodreader cannot be returned. Therefore, I need to convert js files into plain text in batches. For this purpose, I have implemented the following small application:
Copy codeThe Code is as follows:
#-*-Coding: UTF-8 -*-
Import OS
Def rename ():
Path = raw_input ("Enter the path of the folder to be processed ")
Print path
Old_ext = "." + raw_input ("Enter the file type to be processed ")
Print old_ext
New_ext = "." + raw_input ("Enter the file type you want to change ")
Print new_ext
For (path, dirs, files) in OS. walk (path): # traverse the directory tree
For filename in files:
Ext = OS. path. splitext (filename) [1] # obtain the file type. Note that it also carries the dot
Print ext;
If (ext = old_ext ):
Print "----------------"
Newname = filename. replace (old_ext, new_ext)
Oldpath = path + "\" + filename
Newpath = path + "\" + newname
Try:
OS. rename (oldpath, newpath)
Except t BaseException, e:
Print (str (e ))
If _ name _ = '_ main __':
Rename ()