The example in this article describes how Python bulk renames files in the same folder. Share to everyone for your reference. The specific analysis is as follows:
A friend sent a folder over, and the pictures in it were suffix. tmp.
Manual modification is too much work. So write a Python script for batch renaming.
Not familiar with Python's standard library, you can only check the data, or help () side write code.
Three lines of code can solve this problem.
However, no exceptions are caught and all files in the same directory cannot be iterated.
The code is as follows:
?
1 2 3 4 |
Import os for file in Os.listdir ("."): If Os.path.splitext (file) [1] = = ". tmp": os.rename (file, os.path.splitext (file) [0]+ ". jpg" |
Save the code to a file and place it in the folder where you want to rename the file, and run it.
The ability of Python to accomplish this small demand is really nothing to say.
I hope this article will help you with your Python programming.