In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use the python standard library to quickly modify file names, I hope you will learn something after reading this article, let's discuss it together!
Tool: os
First, create a new py file under the movie directory and import os
Import os
Os, a standard library in python, the os module provides a wealth of methods for dealing with files and directories
Os.listdir ('.) # lists the files and folders in the current directory
Note that listdir lists all files and folders
Of course, you can list the files and folders under the specified directory, just change the parameters inside, using both absolute and relative paths.
This method returns a list, and by traversing the list, we can operate on a single file.
By analyzing the file name, we can know some general rules, for example, "[movie Paradise] Episode 1"
This prefix is common to all files, and we can use the string manipulation method rfind in python
Find the location of the last character
Then we get our final value through the interception of the string.
The rename method can change the name of the file.
The first parameter is the name of the original file, and the second parameter is the new name
Reminder * *
Before running the script, print out the new name to see if it is the desired value, and if not, modify the script.
Tags: none
After reading this article, I believe you have a certain understanding of "how to use the python standard library to quickly modify file names". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.