
Build a Desktop File Organizer Using Python
Hey! If you have wanted to build a Python File Organizer but had no idea where to start, you are in the right place. Python File Organizer is cool. You get to sort files.
What We Are Building
We are building a Python File Organizer. It is useful for sorting files.
HTML Structure
Here’s the cool part. HTML is simple.
Let me explain what’s happening here. HTML is used for structure.
CSS Styling
CSS is used for styling. It makes things look good.
Don’t worry about this part. CSS is easy to learn.
How It All Works Together
Step 1: Plan Your Project
Plan your project. Think about what you want to build.
Step 2: Write Your Code
Write your code. Use Python to sort files.
Tips to Customise It
Here are some tips. You can add more features.
Let me explain what’s happening here. You can make it your own.
Learn more about HTML
Pro tip: Keep it simple and have fun!
Conclusion
Celebrate what you just built. You did it!
Share your project with others. Be proud of yourself.
Remember, practice makes perfect. Keep building!
Check out our other tutorials, like Python Requests Library: Blog Thumbnail for Web Development or Python Requests Library: Master Web API Interaction for more learning.
file_organizer.py
import os
import shutil
from datetime import datetime
def organize_files(directory):
# Create directories for each file type
file_types = {
'Documents': ['.txt', '.doc', '.docx', '.pdf'],
'Images': ['.jpg', '.png', '.gif', '.bmp'],
'Videos': ['.mp4', '.avi', '.mov'],
'Audio': ['.mp3', '.wav']
}
for folder in file_types.keys():
if not os.path.exists(os.path.join(directory, folder)):
os.makedirs(os.path.join(directory, folder))
# Move files to their respective directories
for filename in os.listdir(directory):
file_path = os.path.join(directory, filename)
if os.path.isfile(file_path):
file_extension = os.path.splitext(filename)[1]
for folder, extensions in file_types.items():
if file_extension in extensions:
shutil.move(file_path, os.path.join(directory, folder))
break
if __name__ == '__main__':
directory = input('Enter the directory path: ')
organize_files(directory)
print('Files organized successfully!')
