JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Project: File Organizer | JustPaste.app
10 days ago148 views
👨‍💻Programming

Project: File Organizer

Practicing: os, shutil module, loops, conditionals, string methods

Resources:

https://stackview.dev/blog/os-module-in-python/

https://thepythoncode.com/article/file-handling-in-python-using-os-module

https://realpython.com/ref/stdlib/os/

https://realpython.com/ref/stdlib/shutil/

The Scenario

Everyone's Downloads folder eventually turns into chaos — screenshots, PDFs, random files all mixed together with no order. You're going to build a program that scans a folder, figures out what kind of file each item is, and actually sorts them into subfolders automatically.

By the end, running your program on a messy folder should leave it neatly organized into Images/, Documents/, Videos/, and Others/ subfolders.

Before You Start

  1. Create a test folder somewhere safe on your computer — e.g. Desktop/test_folder. Do NOT run this on your real Downloads folder until you're 100% sure it works.

  2. Inside that test folder, create a handful of dummy files with different extensions to test with. You don't need real content — empty files are fine. Example set:

   photo1.jpg
   photo2.png
   report.pdf
   notes.txt
   slides.pptx
   video1.mp4
   randomfile.zip

(On Windows, you can make an empty file quickly by right-clicking → New → and picking the file type, or renaming a blank .txt file's extension.) 3. Have this test folder's full path ready to type in when your program asks for it. Example: C:\Users\YourName\Desktop\test_folder

Step-by-Step Requirements

Build your program to do the following, in this order:

Step 1 — Import what you need

You'll need two modules for this project:

python

import os
import shutil
  • os lets you list files in a folder, check if a folder exists, and create new folders.

  • shutil is what actually moves files from one location to another.

Step 2 — Ask for the folder to organize

Use input() to ask the user for a folder path, and store it in a variable.

Step 3 — Check that the folder actually exists

Before doing anything else, use os.path.exists() inside an if statement to check the folder is real. If it doesn't exist, print a clear error message and don't continue. If it does exist, proceed to the next steps.

Step 4 — Get the list of files in the folder

Use os.listdir() to get every item currently inside that folder, and store it in a variable (this will be a list).

Step 5 — Set up counters

Create four variables, all starting at 0, to keep track of how many files end up in each category: images, documents, videos, and others.

Step 6 — Create the destination subfolders

Before sorting anything, your program should create four subfolders inside the target folder — Images, Documents, Videos, Others — only if they don't already exist. Use os.path.exists() to check, and os.mkdir() to create.

Hint: you'll need to build the full path to each subfolder using os.path.join(), not just the plain name.

Step 7 — Loop through every file and sort it

For each item in your file list:

  • Skip it if it's actually one of your four category folders (so you don't try to sort Images into itself).

  • Skip it if it's a folder rather than a file — use os.path.isdir() to check.

  • Otherwise, check the file's extension using .endswith() and decide which category it belongs to using if/elif/else:

Category

Extensions to check

Images

.jpg, .jpeg, .png, .gif

Documents

.pdf, .docx, .txt, .pptx

Videos

.mp4, .mov, .avi

Others

anything that doesn't match above

Step 8 — Actually move the file

Once you know which category a file belongs to, use shutil.move() to move it from its current location into the matching subfolder. Build the destination path using os.path.join(). Increase the matching counter by 1.

Step 9 — Print what happened, file by file

As each file gets moved, print a line confirming it — e.g. "Moved: photo1.jpg -> Images/"

Step 10 — Print a final summary

After the loop finishes, print a clean summary showing:

  • How many files were moved into each category

  • The total number of files organized

Expected Sample Output

Enter the folder path to organize: C:\Users\Student\Desktop\test_folder
Moved: photo1.jpg -> Images/
Moved: photo2.png -> Images/
Moved: report.pdf -> Documents/
Moved: notes.txt -> Documents/
Moved: slides.pptx -> Documents/
Moved: video1.mp4 -> Videos/
Moved: randomfile.zip -> Others/

----- FOLDER SUMMARY -----
Images moved: 2
Documents moved: 3
Videos moved: 1
Others moved: 1
Total files organized: 7

After running it, open your test folder — you should now see four new subfolders, each containing the correct files, and the original messy file list should be gone from the main folder (moved, not copied).

Checklist Before You Submit

  • Program asks for a folder path

  • Program checks the folder exists before continuing

  • Program creates the 4 subfolders if they don't exist

  • Program correctly skips folders (doesn't try to sort them)

  • Every file gets sorted into the correct category based on extension

  • Files are actually moved (check your test folder to confirm!)

  • A confirmation line prints for each file moved

  • A summary with counts per category prints at the end

  • Tested on the sample test folder — NOT on a real, important folder

Common Mistakes to Watch For

  • Forgetting os.path.join() — writing folder + "Images" instead of os.path.join(folder, "Images") will produce a broken path on some systems.

  • Not skipping folders — if you don't check os.path.isdir(), your program will crash trying to "move" a folder using the file-sorting logic.

  • Running it twice on the same folder — after the first run, all files are already inside subfolders, so running it again on the same folder will find nothing left to sort at the top level. This is expected, not a bug.

  • Case sensitivity — .JPG (uppercase) won't match .endswith(".jpg"). If you want to catch both, check for both cases or convert the filename to lowercase first with .lower() before checking.

Submission

Save your file as LastName_FirstName_FileOrganizer.py and submit via MSTeams. Make sure your final tested version is the one submitted — your test folder does NOT need to be submitted, just your code.

← Back to timeline