This article mainly introduces how to modify the file suffix in Python in batches. if you need it, you can refer to the many tutorials you have downloaded recently. Unfortunately, the suffix names are all ". mp4 ", and I like ". rmvb "suffix, due to slight cleanliness, cannot stand the following ". mp4 ", but manual modification is too cumbersome, so use the Python you just learned to be lazy! :)
Name of the file before running the program
What we need to do is to create a python file in the current directory, such as demo2.py, and then open it in the editor and type the following code:
The code is as follows:
Import OS
# List all files in the current directory
Files = OS. listdir (".")
For filename in files:
Portion = OS. path. splitext (filename)
# If the suffix is .txt
If portion [1] = ". mp4 ":
# Recombine the file name and suffix
Newname = portion [0] + ". rmvb"
OS. rename (filename, newname)
Okay. save and run your program!
You will be surprised to find that:
Haha, all files suffixed with ". mp4" should be suffixed with ". rmvb !!!