![]() ![]() We will use a method called os.walk(path) for traversing through the subfolders of a folder.įollow the below steps to write code for the deletion files/folders based on the number of days. You can find more details about the epoch here. All the methods return time in seconds since the epoch. We have a method called stat in the os module that gives details of last access (st_atime), modification (st_mtime), and metadata modification (st_ctime) time. Often you don’t need old logs, and you regularly need to clean them to make storage available. Note: the following are tested on Python 3.6+ Removing files/folders older than X days Writing scripts for completing a specific system task is a cupcake if you know Python. We can replace any annoying or repetitive system tasks using Python. We are going to use this module to complete our automation of deleting the files. Python has a module called os that helps us to interact with the operating system.You can run the same code in Windows, Linux, and Mac. Python is compatible with all the operating systems.Less code compared to other programming languages.Python is an all-time favorite language for automating tasks.First, you should know why Python is a good choice. We are going to take advantage of Python to finish our task without any obstacle. Python is an excellent programming language for scripting. Here comes Python to make our lives easier. Automate them!ĭeleting files and folders manually is not an exciting task, as one may think. ![]() Cleaning file system regularly manually is not good. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |