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 > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you the relevant knowledge points about how to achieve batch file classification and preservation by Python. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Here we take more than two hundred original world files as an example.
The code shows import osimport timeimport datetimeimport pprintimport shutilimport reorigin_dir = 'original file /' target_dir = 'target file /' files = os.listdir (origin_dir) month_compile = re.compile ('(20\ d\ d) ([01] [0-9])') print (files) file_dict = {} for file in files: if file.endswith ('.docx'): word_file = os.path.join (origin_dir) File) month = month_compile.search (word_file) if month: month = month.groups () # print (month.groups ()) if month [- 1] = ='00: month = re.search ('(20\ d\ d) 0 ([01] [0-9]))' Word_file) .groups () T1 ='- '.join (month) if T1 in file_dict.keys (): file_ requests [T1] .append (word_file) else: file_ requests [T1] = [word_file] pprint.pprint (file_dict) if not os.path.exists (target_dir): os.mkdir (target_dir) ) # Mobile file for key in file_dict.keys (): # month in which the file was created new_file_dir = os.path.join (target_dir Key) if not os.path.exists (new_file_dir): os.mkdir (new_file_dir) for file in file_dict [key]: # get the file name new_file_name = os.path.basename (file) # merge the new file path new_file_path = os.path.join (new_file_dir New_file_name) print (new_file_name) shutil.copyfile (file, new_file_path) effect display
Here we take month classification as an example to automatically create folders for classification.
Look, it's easier to find.
The above is all the contents of this article "how to achieve batch File Classification and Storage in Python". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.