Building an Automated File Sorter in File Explorer using Python | Python Projects for Beginners

preview_player
Показать описание

In this tutorial we are going to walk through how to create a File Sorter using Python. This will allow us to automate the sorting of our files without having to drag and drop files into folders.

____________________________________________

SUBSCRIBE!
Do you want to become a Data Analyst? That's what this channel is all about! My goal is to help you learn everything you need in order to start your career or even switch your career into Data Analytics. Be sure to subscribe to not miss out on any content!
____________________________________________

RESOURCES:

Coursera Courses:

Udemy Courses:

*Please note I may earn a small commission for any purchase through these links - Thanks for supporting the channel!*
____________________________________________

BECOME A MEMBER -

Want to support the channel? Consider becoming a member! I do Monthly Livestreams for Members and you get some awesome Emoji's to use in chat and comments!

____________________________________________

Websites:
📱Instagram: @Alex_The_Analyst
____________________________________________

*All opinions or statements in this video are my own and do not reflect the opinion of the company I work for or have ever worked for*
Рекомендации по теме
Комментарии
Автор

shutil is called "shell utilities" because it allows you to perform various file-related tasks that are similar to the commands that you might use in a Unix shell, such as copying, moving, renaming, and deleting files and directories.

ChronicleContent
Автор

Instead of getting rid of the \ in lieu of the /, you can add an additional \\ at the the of the path in order to make it an escape character.

Alex, this video was awesome!

nesternunez
Автор

Alex! Another project is completed! Every new step in your bootcamp increases my curiosity to go further. I am really into it. :) Again, many thanks for your time and knowledge. I have never been so involved in IT education as I am now with your teaching approach

andreymoroz
Автор

Hey Alex! I know you get so much of these comments already but I just wanna say thank you for creating these tutorials! I've been faithfully following your Excel, Tableau and Python tutorial and they all really help me understand better than some paid courses I've been through. Cheers!

carocahyadi
Автор

It has been 5 years since I coded but I finally did a step one by following your tutorial.
I am super thankful for it!

Intel
Автор

This is a very good tutorial, I appreciate all the work you put into each video

I modified the program to extract the file extensions of each file.
- Create a folder based on each individual unique extension - (used sets)
- Move files to their respective folders based on their extensions.
- I hope I learn app development so I can create this into a full application for use.

arnoldochris
Автор

This was a FANTASTIC video! I learned SO much and I loved how you walked us through all the steps like you do in all your videos. You're a pro and an EXCELLENT teacher! As always, THANK YOU ALEX!!

sj
Автор

This is so awesome. I feel like a magician! Thanks, Alex!

jh
Автор

When I was learning python last year I did this to myself, cause I needed it for my downloads folder, you did it in 16 minutes I was there for like 3 weeks hahaha

Working
Автор

A small program that helps presenting all available extensions in our "listdir" :

def extension(x):
i = 0
while i < len(x) :
if x[i] == "." :
return x[i+1:]

i=i+1

return ""

extension_list = list(map(exsention, a))



print(extension_set)


# <a> is the list resulted from the fonction os.listdir

AbdessamadALIRABAH
Автор

Hi Alex!

I`ve tried to do something similar based on your video. The task I've set was: I have a lot of files which names have identical beginning in my Downloads and I have tried to move them all to a single folder.

Here's what I`ve tried to do and it has worked (not from the first try, to tell the truth, but still).

import os, shutil
path =
file_name = os.listdir(path)
os.makedirs(path + 'Credit notes')
for file in file_name:
if 'invoice_print_' in file:
shutil.move(path + file, path + 'Credit notes/' + file)

That's why your channel is a box of wonders for me! Thank you for your content and wish you lots of luck!

ivanko-nebo
Автор

This video is amazing I used this algorithm to separate the vidoes and images to different folders with learning and without effort . Thank you 😆😆

clovisstanford
Автор

Excellent, simple easy tutorial, Thanks!

neildelacruz
Автор

This tells me python is such a powerful tool everyone must learn

saidimbondela
Автор

This is very nice way to sort all the files in the folder. I modified the program a little, and allowed it to read all files from the folder and generate the folder name based on the file extension. This way we can eliminate the hard code folder names.
I have also used os.path.join() method to join the file paths without using '/', which is again a good practice when working with files.

KANOJIARICHA
Автор

You are amazing, your my super hero.
This playlist/Bootcamp is very helpfull 🙂

chintalapatisriharshavarma
Автор

Hi Alex! I really appreciate all these videos that you've posted. I'm still getting a bunch of errors with this though, and I'm not able to see on the video where I'm making errors. Is this posted on your github somewhere? I'm sure I'm missing punctuation or something that I'm just not able to see on the video.

RonanJozwiak
Автор

here's a better version where you dont have to hard code the folder names and file types : import os
import shutil

# Path where the files are located and where folders will be created
path =

# Get all file names in the specified directory
file_names = os.listdir(path)

# Initialize a set to hold unique file extensions
file_extensions = set()

# Populate the set with file extensions (in lowercase to avoid duplicates due to case differences)
for file_name in file_names:
if os.path.isfile(os.path.join(path, file_name)): # Ensure it's a file, not a directory
extension =
if extension: # Ensure there is an extension


# Create folders for each file type if they don't already exist
for ext in file_extensions:
folder_name = ext[1:] + " files" # Remove the dot from extension and add ' files'
folder_path = os.path.join(path, folder_name)
if not os.path.exists(folder_path):
os.makedirs(folder_path)

# Move files to their respective folders
for file_name in file_names:
# Skip directories
if os.path.isdir(os.path.join(path, file_name)):
continue

# Get the file extension and corresponding folder name
file_extension =
if file_extension:
folder_name = file_extension[1:] + " files"
target_folder_path = os.path.join(path, folder_name)

# Full path for the file's current location and the target location
current_file_path = os.path.join(path, file_name)
target_file_path = os.path.join(target_folder_path, file_name)

# Move the file if it's not already in the target folder
if not
shutil.move(current_file_path, target_file_path)

rakibhasanrahad
Автор

If you're a mac user, I'd expect to hit a snaffu. I personally get a * next to the file name and when I print. I think it's because the mac file paths use a bunch of "%20".

ylgoydc
Автор

was a great one, but I would rather refactor the code in a way to avoid getting too many if statements spread out in the code, just to keep redundancy away from it. Subscribed!

Mrnafuturo
visit shbcf.ru