This article describes how to rename files in the same folder in Python in batches, and describes how to use the OS module to operate files in Python, for more information about how to batch rename files in the same folder in Python, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
A friend sent a folder and all the images in it were suffixed with. tmp.
Manual modification requires too much work. Therefore, a Python script is written for batch renaming.
Not familiar with the Python standard library, you can only query the information, or help () while writing 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:
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. Run the command.
There is nothing to say about Python's ability to meet this small requirement.
I hope this article will help you with Python programming.