Python Project for Class 11- Folder Manager

Python Project for class 11 Folder Manager is based on Python Dictionary and some simple python libraries like Tkinter, Sys, OS.  This Python Project for class 11 scans the whole directory and subdirectories recursively for the given type of files and move similar type of files in desired folders.  Tkinter is used here for the visual folder selection and completion message.

Python Project for class 11

Tkinter project for class 11- Text Editor

Here is the screenshot of our folder that contains all type of files

How to Run Folder Manager

Copy Paste the given python program for folder Management in your favorite Python IDE and run it. Make it very sure you have Tkinter installed in your system. The system will prompt you for the folder selection. Select the folder you want to manage.

Within seconds the Folder Manager will finish its processing and flash the completion message.

Now your selected folder will look like this.

Here is the source code of the folder manager written in python. OS.walk() function used in this project for scanning all the files recursively from the source directory. You can learn more about Python OS modules from its official repository.

#   Python program to arrange files according to their file types
#   made by             : rakesh kumar
#   last compiled on    : 30/11/2019

import os.path
from os import path
import sys
import shutil
import tkinter as tk
from tkinter import filedialog
import tkinter.messagebox


filetype = {'docs': ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'rtf', 'odf', 'odt'],
            'pdf':  ['pdf'],
            'img':  ['jpg', 'jpeg', 'png', 'gif', 'bmp'],
            'exe':  ['zip', 'rar', 'exe'],
            'prg':  ['py', 'cpp', 'php'],
            'music': ['mp3', 'mp4', 'mkv', 'wmv', '3gp', 'avi', 'mov', 'aac', 'flv', 'mpg']
            }


def filemove(file, filetype, key):
    if(file.split('.')[1]) in filetype[key]:
        if (os.path.exists(sourcedir+'/'+key) == False):
            os.mkdir(sourcedir+'/'+key)
        elif(path.isfile(sourcedir+'/'+key)):
            os.mkdir(sourcedir+'/'+key)
        try:
            shutil.move(sourcedir + "/"+file, sourcedir+'/'+key)
        except:
            pass


root = tk.Tk()
root.withdraw()
sourcedir = filedialog.askdirectory()  # source folder
if not sourcedir.strip():
    print("Folder Error...User did not selected any folder")
    #rootdir = 'C:\\Users\\ace
    sys.exit()

for root, folder, files in os.walk(sourcedir):
    for file in files:
        for key in filetype.keys():
            if(file.split('.')[1]) in filetype[key]:
                filemove(file, filetype, key)

tkinter.messagebox.showinfo('Folder Manager', 'Please check your Folde now')

Here in the python project for class 11, you can see we have taken folderName dictionary keys and its associated files its values. walk through the folder recursively and based on the files generated folders using dictionary key and later on move associated files in that folder.

Related Posts

If you like CBSEToaday and would like to contribute, you can also write an article using submit article or mail your article to contribute@cbsetoday.com See your article appearing on the cbsetoday.com main page and help other students/teachers.