Python bulk modifies file name suffix name

Source: Internet
Author: User

#coding: Utf-8
Import OS

# list all files in the current directory
Files = Os.listdir ('. ')
For filename in Files:
# split file name and suffix name
Portion = os.path.splitext (filename)
# Compare suffix names
If portion[1] = = ". mp3":
# Modify suffix Name
newname = portion[0] + ". M4A"
Os.rename (filename, newname)
# Print out filename-20 for left-aligned, width 20
Print ("%-20s ===>%20s"% (filename, newname)

The following results are performed:

Just want to marry you. mp3 ===> just want to marry you. m4a
I just want to think about you. mp3 ===> just want to remember you. m4a
Well? Do you regret it? MP3 ===>, huh? Do you regret it? m4a
Hehe, I'm crazy. mp3 ===> hee, I'm crazy. m4a
Hey, let's go out for a meeting. mp3 ===> Hey, go out for a meeting. M4A
In Thailand you are most likely to be ...? MP3 ===> in Thailand are you the easiest to be ...? m4a
Summer chic: Holiday style. mp3 ===> Summer chic: Holiday style. m4a
All right, come on, don't be ridiculous. mp3 ===> All right, stop talking nonsense. m4a
How to be more disappointed in life. mp3 ===> How to be more disappointed in life. M4A
Baby, your makeup. mp3 ===> Baby, your makeup flower. m4a
What is the escape of the Chamber of Secrets? MP3 ===> The Secret room escape is a what. m4a

Python bulk modifies file name suffix name

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.