Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create folders automatically according to time in Python

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to automatically create folders according to time in Python, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Introduction

Too many computer desktop files take time to find, and messy computer desktops will also affect the mood at work, so use python to automatically create a folder of the day according to time, so you can store files on the desktop according to time.

Code implementation # _ * _ coding:utf-8_*_import osimport datetimedef create_folder (path): #-month-day hours: minutes: now_time = datetime.datetime.now (). Strftime ("% Y-%m-%d% H:%M:%S") # year = datetime.datetime.now (). Strftime ('% Y') #-month month = datetime.datetime.now (). Strftime ('% Ymuri% m') #-month-day day = datetime.datetime.now (). Strftime ('% Ymuri% m% d') # minutes: hour = datetime.datetime.now (). Strftime ("% H:%M:%S") print (now_time + "\ n" + day + "\ n" + hour) foldername = path+ "\" + year+ "\" + month+ "\" + day # print (pwd) # File path word_name = os.path.exists (foldername) # determine whether the file exists: there is no creation if not word_name: os.makedirs (foldername) if _ _ name__=='__main__': path=r'D:\ work' # folder creation location create_folder (path) program package

Publish the py program as an exe executable file, double-click to run on the window system

Pyinstaller-F create_folder.py

You can also put the exe file in the window self-startup folder so that you can open the computer and automatically create a date folder.

Effect display

The above is all the contents of the article "how to create folders automatically according to time in Python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report