#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