Batch modification file suffix name

Source: Internet
Author: User

This program is supported under Windows and Linux

The following programs can modify the file suffix name in bulk:

#!/usr/bin/env python
#coding: UTF8

#批量修改一个文件下的文件后缀
 sys
os
Rename ():
    #Path = "z:\\test\\"             # Windows file directory
    Path = raw_input ("Please enter the directory you want to manipulate (format like ' z:\\test '):")
    FileList = Os.listdir (Path)
    filelist:
        olddir = Os.path.join (path,files)
         files
        #打印出老的文件夹里的目录和文件 os.path.isdir (olddir):    #判断是否是文件, is a file that skips
             Continue
filename = os.path.splitext (files) [0] #filetype        
        = os.path.splitext (Files ) [1]
        newdir = os.path.join (Path,filename + '. jpg ')    #只要修改后缀名就可以更改成任意想要的格式
        os.rename (Olddir,newdir)
Rename ()

Newdir = Os.path.join (Path,str (Random.randint (1,1000)) +filetype)    #可以修改文件名为随机名称

Is that the file already has an error, the file to be changed to the name already exists, to change a conflicting name on it.

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.