
Hey, let’s build a Python File Organizer!
We are building a Python File Organizer to automate our messy downloads folder.
What We Are Building
This project is cool! It helps you organize your files.
Python Implementation
We’ll use Python to create the file organizer. Python is a great language for this task.
How the Python File Organizer Works
Here’s the cool part: we’ll use Python scripts to automate the process.
Step 1: Set Up Your Project
First, set up your project. Don’t worry about this part, it’s easy!
Step 2: Write the Python Script
Now, write the Python script. Let me explain what’s happening here: we’re using Python to move files.
Pro tip: use the MDN documentation for help with Python.
How It All Works Together
We’ll use the Python script to organize our files. It’s easy and fun!
Step 3: Run the Script
Run the script and see the results. You’ll be amazed!
Tips to Customise It
Here are some tips to customize your Python File Organizer: add more features, change the design, and more!
Check out this Desktop File Organizer Python Script for more ideas.
Remember, practice makes perfect! Don’t be afraid to try new things.
Learn more about the Python Requests Library for web development.
Conclusion
Congratulations, you built a Python File Organizer! Share your project with the world and be proud!
Read more about Python File Organizer Script and other projects on our website.
file_organizer.py
import os
import shutil
from datetime import datetime
# Define the downloads folder path
DOWNLOADS_FOLDER = '/Users/username/Downloads'
# Define the folders to organize
FOLDERS = '
Documents,
Images,
Videos,
Music,
Archives
'
# Create the folders if they do not exist
for folder in FOLDERS.split(','):
folder = folder.strip()
folder_path = os.path.join(DOWNLOADS_FOLDER, folder)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
# Organize the files
for filename in os.listdir(DOWNLOADS_FOLDER):
file_path = os.path.join(DOWNLOADS_FOLDER, filename)
if os.path.isfile(file_path):
# Get the file extension
file_extension = os.path.splitext(filename)[1][1:]
# Move the file to the corresponding folder
if file_extension in ['doc', 'docx', 'pdf', 'txt']:
shutil.move(file_path, os.path.join(DOWNLOADS_FOLDER, 'Documents'))
elif file_extension in ['jpg', 'png', 'gif', 'bmp']:
shutil.move(file_path, os.path.join(DOWNLOADS_FOLDER, 'Images'))
elif file_extension in ['mp4', 'avi', 'mov', 'wmv']:
shutil.move(file_path, os.path.join(DOWNLOADS_FOLDER, 'Videos'))
elif file_extension in ['mp3', 'wav', 'ogg']:
shutil.move(file_path, os.path.join(DOWNLOADS_FOLDER, 'Music'))
elif file_extension in ['zip', 'rar', '7z']:
shutil.move(file_path, os.path.join(DOWNLOADS_FOLDER, 'Archives'))
