Chapter 5
Automating File Management
IN THIS CHAPTER
Getting rid of old and temporary files
Backing up files in bulk
Eliminating duplicate files
Compressing and decompressing files
In this chapter, you explore more techniques for navigating through directories and subdirectories to automate file management. The powerful pathutil and shutil modules make quick work of many mundane, time-consuming tasks. You discover scripts for dealing with old and temporary files, backing up files, removing duplicate files, and more.
Deleting Old and Temporary Files
This script can delete old and temporary files. In fact, it can delete files of any age, which, of course, could be dangerous. To play it safe, we won’t let this script actually delete any files. Instead, we’ll have it send the files to the trash — that is, to the Recycle Bin in Windows or to the Trash on Linux or macOS. That way, you can review all the files, and recover any files you want to keep before deleting them forever.
Luckily, sending to the trash is easy thanks to the send2trash module. This cross-platform module determines ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access