Folder sorter according to files extensions using Python

Many of you might have come across the situation where you want to find a file in a directory and when you open that directory, it is messed up with all kinds of files. It is really difficult to locate the required file. How nice it would be if we can have all the files with the same extension in one directory! The job of finding the file would get simpler and it would look pretty good as well.

This problem is solved by Python. Using Python os and shutil module we can easily sort the files with the same extension and store them in separate folders.

Read more..

Folder sorter project description

To understand the concept of the project in a better way imagine that a folder is completely messed up with files of all kinds of extensions (.txt, .mp4, .csv, etc). Finding a particular file from this huge ocean of files is very tough.

After running the python script on the above folder, directories with extension names are created and files with the same extension are moved to the corresponding directory.

Python Modules used for projects:

To build this project we have to make use of two Python-modules namely: os-module and shutil-module.

Brief about them is :

OS – Module: os –module provides all the functionalities of interacting with the operating system. It provides a portable way of interacting with os dependent functionalities.  os –module comes under python’s standard utility modules.

Shutil –module: The shutil module is used to manipulate the high-level operations on files and collections of files. In simpler words, shutil module is used to copy, move or remove files. It also comes under the Python standard utility module. The function that we are going to use in our project is shutil.move(src,dest). This function recursively moves a file or directory from source to a given destination. If the destination directory already exists, then the source is moved inside it. But if destination already exists but it is not a directory then it may be overwritten depending upon os.rename() semantics.

Latest projects on Python

Want to develop practical skills on Python? Checkout our latest projects and start learning for free

Project Implementation

For the actual implementation of the project, we need to follow the following steps:

  • Create a list of all the filenames in an organized list that are present in the specified directory.
  • In this step iterate through every file and do the following steps according to the conditions.
  • Create a list which contains only extensions (without ‘ . ’ like txt and not ‘ .txt ’ )
  • Now there can be three cases, the first one is if the file itself is a directory. In this case, just continue to iterate.
  • Second case if ‘ ext’ directory already exists. In such a case simply move the source file to the destination.
  • Third case is if ‘ ext ’ directory does not exist, then simply create 'ext’ directory and move all the files with ‘ext’ extension in that directory.
  • Repeat the step 5,6,7, for all files in that directory.
  • After completing the loop, you will have the folders with extension as their name which would include files with the same extensions.

Software requirements: Text Editor (preferably Sublime Text), Python3.

Programming Languages: Python, OS-module, shutil module.

How to build Python projects Did you know

Skyfi Labs helps students learn practical skills by building real-world projects.

You can enrol with friends and receive kits at your doorstep

You can learn from experts, build working projects, showcase skills to the world and grab the best jobs.
Get started today!

Kit required to develop Folder sorter according to files extensions using Python:
Technologies you will learn by working on Folder sorter according to files extensions using Python:
Folder sorter according to files extensions using Python
Skyfi Labs Last Updated: 2022-03-19

Join 250,000+ students from 36+ countries & develop practical skills by building projects

Get kits shipped in 24 hours. Build using online tutorials.

More Project Ideas on Python

Face recognition using Raspberry Pi
Linux Based Medication remainder
Ultrasonic beats player
Automated door opener with lighting control
IoT based theft detection using Raspberry Pi
Wheelchair wih safety system
Raspberry Pi osilloscope
Health monitoring using Raspberry pi
Automatic Green house system
Wheel combined robotic suspension system
Bank Account Management System using SQL and C++
Content Aggregation Project using Python
URL Shortener
Develop An Expense Tracking System using Python
Mp3 Player using Python
Simple Chat room using Python
Folder sorter according to files extensions using Python
Batch Image editor using Python
Password Generator and Manager using Python
Web Scrapper (Amazon Price Tracker)
Bird Species detection using Python
Develop An Online CV Builder using Python
Online Job Portal using Python and SQL database
Social Media Site using Python (Django)
Driver Drowsiness detection using Python
Traffic recognition using python
Website Blocker using python
Speech Emotion Recognition using Python
Speed Typing test with Python
Gender and Age Detection using Python
Pharmacy management using Python
Virtual Notebook - Python project
Find My Professor
How to Develop a TIC TAC TOE game using Python
Admission tracking system
Assignment submission system using Python
Smart feedback system using Python
Data collection tool using Python
Language translator and converter using Python
Automatic Brand LOGO detection using Python
Rock, paper, scissor game using python
Youtube video downloader with Tkinter UI python project
Instagram bot using python
Desktop notifier app using python
Spotify song downloader using python
Jarvis Personal assistant using Python
Sound processing python project
Develop a Supermarket Billing System with Python
Desktop voice assistant project

Subscribe to receive more project ideas

Stay up-to-date and build projects on latest technologies