Python bulk modify file suffix sample code sharing _python

Source: Internet
Author: User

The ipad goodreader to JS file support is not very good, although can read it but always unable to exit, not return to the GoodReader of the main interface, so I need to turn the JS file batch into plain text. For this purpose, I've got one of the following small apps:

Copy Code code as follows:

#-*-Coding:utf-8-*-

Import OS
def rename ():
Path = raw_input (Please enter folder path to process)
Print path
Old_ext = "." +raw_input ("Please enter the file type to be processed")
Print Old_ext
New_ext = "." +raw_input ("Please enter the file type you want to become")
Print New_ext
For (path, dirs, files) in Os.walk (path): #遍历目录树
For filename in Files:
ext = os.path.splitext (filename) [1] #取得文件类型, notice it's got a 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 Baseexception, E:
Print (str (e))

if __name__ = = ' __main__ ':
Rename ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.