Chapter 9. Organizing Files

In the previous chapter, you learned how to create and write to new files in Python. Your programs can also organize preexisting files on the hard drive. Maybe you’ve had the experience of going through a folder full of dozens, hundreds, or even thousands of files and copying, renaming, moving, or compressing them all by hand. Or consider tasks such as these:

  • Making copies of all PDF files (and only the PDF files) in every sub-folder of a folder

  • Removing the leading zeros in the filenames for every file in a folder of hundreds of files named spam001.txt, spam002.txt, spam003.txt, and so on

  • Compressing the contents of several folders into one ZIP file (which could be a simple backup system)

All this boring stuff is just ...

Get Automate the Boring Stuff with Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.