From the course: Using Python for Automation

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Organize directories with Python

Organize directories with Python - Python Tutorial

From the course: Using Python for Automation

Organize directories with Python

- Ready to get your files in tip-top shape? Python can be so handy to sort and streamline your files and directories. In this lesson, you'll explore how to use Python to organize file directories. Now head to your exercise files, and check out the organize_me folder in your file system. Your goal is to create a program that generates new directories for each file type and organizes this directory. Next, open the organize_me folder in VS Code, and go to organize_starter_code.py. At the top, the first import statement imports the OS library, which contains functions for interacting with your operating system. Then the second import statement imports the path function from the pathlib library. Next, a dictionary named subdirectories is defined. It maps four basic categories: documents, audios, videos, and images, two lists of specific file types. Then a function named organizeDirectory is defined. This takes in a value that represents a file suffix it can encounter, and returns a…

Contents