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

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ต.ค. 2024

ความคิดเห็น • 83

  • @ChronicleContent
    @ChronicleContent ปีที่แล้ว +107

    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.

    • @jeancazilus8314
      @jeancazilus8314 ปีที่แล้ว +6

      Thanks for the explanation !! Very informative 👌🏾

  • @nesternunez8430
    @nesternunez8430 ปีที่แล้ว +22

    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!

  • @carocahyadi94
    @carocahyadi94 ปีที่แล้ว +7

    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!

  • @andreymoroz8204
    @andreymoroz8204 ปีที่แล้ว +12

    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

  • @Intel626
    @Intel626 11 หลายเดือนก่อน +2

    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!

  • @arnoldochris5082
    @arnoldochris5082 11 หลายเดือนก่อน +2

    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.

  • @sj1795
    @sj1795 10 หลายเดือนก่อน +1

    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!!

  • @Working800
    @Working800 ปีที่แล้ว +3

    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

  • @clovisstanford6515
    @clovisstanford6515 8 หลายเดือนก่อน

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

  • @saidimbondela9158
    @saidimbondela9158 ปีที่แล้ว +1

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

  • @AbdessamadALIRABAH
    @AbdessamadALIRABAH ปีที่แล้ว

    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))
    extension_set=set(extension_list)
    print(extension_set)
    # is the list resulted from the fonction os.listdir

  • @jh1896
    @jh1896 หลายเดือนก่อน

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

  • @ivanko-nebo
    @ivanko-nebo ปีที่แล้ว +2

    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 = r"C:/Users/idemianenko/Downloads/"
    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!

    • @heritage1834
      @heritage1834 ปีที่แล้ว

      This is nice 👍

    • @courtenayboyle4329
      @courtenayboyle4329 ปีที่แล้ว

      awesome!

    • @rsukut5866
      @rsukut5866 ปีที่แล้ว

      That's pretty fantastic, and seems like a perfect real-life application! Thank you for sharing this.

  • @neildelacruz6059
    @neildelacruz6059 ปีที่แล้ว +1

    Excellent, simple easy tutorial, Thanks!

  • @Kaura_Victor
    @Kaura_Victor 6 หลายเดือนก่อน +2

    I've written these codes as it is on the tutorial but it's not running as expected. It's giving me a lot of error messages.

    • @kaylaesezobor9258
      @kaylaesezobor9258 6 หลายเดือนก่อน

      It's not even giving me anything

  • @KANOJIARICHA
    @KANOJIARICHA 5 หลายเดือนก่อน

    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.

    • @aisyahmokhtar4616
      @aisyahmokhtar4616 4 หลายเดือนก่อน

      if you dont mind, can you share the script that allows you to not hard code the folder names and just generate the folder name based on the file extension? i would love to learn this method too. thank you for sharing!

  • @CaitlinLemon-s6v
    @CaitlinLemon-s6v 11 หลายเดือนก่อน +1

    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".

  • @rakibhasanrahad6994
    @rakibhasanrahad6994 7 หลายเดือนก่อน +3

    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 = r"......../"
    # 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 = os.path.splitext(file_name)[1].lower()
    if extension: # Ensure there is an extension
    file_extensions.add(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 = os.path.splitext(file_name)[1].lower()
    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 os.path.exists(target_file_path):
    shutil.move(current_file_path, target_file_path)

  • @cozimbatman4100
    @cozimbatman4100 2 หลายเดือนก่อน

    a fun project would be to read the extensions for each file from file_name and creating the folder(if not exists) and then move the files into the respective(if not exists)

  • @chintalapatisriharshavarma2575
    @chintalapatisriharshavarma2575 5 หลายเดือนก่อน

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

  • @Mrnafuturo
    @Mrnafuturo ปีที่แล้ว

    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!

  • @RonanJozwiak
    @RonanJozwiak หลายเดือนก่อน

    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.

  • @chaayoub5360
    @chaayoub5360 ปีที่แล้ว +1

    thank you. but i think you forget to add video about how to clean data using python

  • @Charlay_Charlay
    @Charlay_Charlay 10 หลายเดือนก่อน

    I got it to work!!! Thanks Alex!

  • @ToVods
    @ToVods ปีที่แล้ว +4

    Hi Alex I would like to thank you for all of the effords you went through to help everyone.I really appriciate you.I don't live in US but Do you think with a portfolio that has up to 10 different projects, i can land an interview on linkedin for a remote job?

    • @ruthshada2752
      @ruthshada2752 ปีที่แล้ว +1

      In the same situation here, I don’t live in the us and trying to land interviews for a remote job. How is it going for you so far ?

  • @lil_dejix9144
    @lil_dejix9144 2 หลายเดือนก่อน

    I'm just wondering won't it be more dynamic to make the range in the for loop Len(folder_names) ?

  • @Bac2277
    @Bac2277 ปีที่แล้ว +1

    Hey Alex, I do not find live server in visual studio extensions. How should I get it?

  • @falahoudinesaid6973
    @falahoudinesaid6973 5 หลายเดือนก่อน

    hello Alex ?
    Thank you for the tutorial.
    One question please what about PDF file?

    • @wahyuprasetyo6098
      @wahyuprasetyo6098 3 หลายเดือนก่อน

      1. add 'PDF Files' in folder_name list
      2. change the range to (0, 4)
      3. add to loop:
      elif '.pdf' in file and not os.path.exists(path + 'PDF Files/' + file):
      shutil.move(path + file, path + 'PDF Files/' + file)

  • @frothylube491
    @frothylube491 ปีที่แล้ว +2

    Hey Alex! I know this isn’t exactly related to the video but I have a question. Do you think a company would hire someone as a data analyst, if all they had were mere basics? Simply they didn’t have a degree in the area, perhaps a certification, but they had a driving spirit to learn. Or are most people, even for entry level positions, expecting you to just drop into the seat and go off with little to no extra help?

    • @atxvet
      @atxvet ปีที่แล้ว +10

      I just happened to pop in and saw your question, so let me take a crack at answering as an Old who hires people. Short answer: Yes. What sets an entry level/junior analyst candidate apart is not their technical abilities but their critical thinking and CURIOSITY. If I give you a pile of data, I want your eyes to light up at the prospect of EDA. I expect whatever you give me to be full of mistakes and flawed logic -- and that's FINE, as long as I see that the lights are on upstairs and you have asked the data lots of interesting questions. Critical thinking, curiosity, interested, and interesting. That's what I'm after. Good luck!

    • @frothylube491
      @frothylube491 ปีที่แล้ว +3

      @@atxvet I appreciate the response! I just finished the Google certification, and I’m working on doing more projects. My worry is that since I’m still only 5 months on from beginning to learn Data Analytics is that no one will give me a chance. All I’m really wanting is for a hiring manager to see my interest and drive then give me a shot, even if my skills are very…..beginner. Help train me with someone by my side and i will give 200% on everything to prove I’m taking this seriously. I just don’t know anyone, personally, in the field to ask any questions, so I’ve been hesitant on replying.

  • @sarkersaadahmed
    @sarkersaadahmed 7 หลายเดือนก่อน

    8:05 you can alsso use \\ instead of /

  • @TrickzHD
    @TrickzHD 10 หลายเดือนก่อน

    How would I go a step further that it goes automatically every like day or so?

  • @Mohammad-tw7cq
    @Mohammad-tw7cq ปีที่แล้ว

    The PCWizKid mouse cursor is a classic.

  • @iyaszawde
    @iyaszawde 7 หลายเดือนก่อน

    Thanks a lot ❤️, could anyone tell me how to make an execution for this script each day, please!

  • @victoradekunlecom
    @victoradekunlecom ปีที่แล้ว +1

    Damn! Alex is so real. Can we write a program to automatically detect the file formats, create folders and sort them accordingly? Because I feel it could be difficult to manually detect and name the folders if the list is endless. Sounds like a clustering thing in machine learning but I'm not sure. Please what do you think?

    • @Bomyism
      @Bomyism ปีที่แล้ว +6

      I've asked ChatGPT to do it and voilà:
      import os
      import shutil
      # specify the directory you want to sort
      source_directory = r"C:\Users\Username\Documents\Sort Me"
      try:
      # get a list of all files in the source directory
      file_list = os.listdir(source_directory)
      # create a folder for each file extension
      for file_name in file_list:
      file_extension = os.path.splitext(file_name)[1][1:]
      destination_folder = os.path.join(source_directory, file_extension)
      if not os.path.exists(destination_folder):
      os.makedirs(destination_folder)
      # move the file to the appropriate folder
      source_path = os.path.join(source_directory, file_name)
      destination_path = os.path.join(destination_folder, file_name)
      shutil.move(source_path, destination_path)
      except Exception as e:
      print(f"An error occurred while sorting the files: {e}")

  • @TheDanzo96
    @TheDanzo96 ปีที่แล้ว +2

    When you had the 'Else' statement and it returned the message 4 times would that have been because of the 3 folders? I think it may have counted those as a "file" in the folder

    • @sagarpatel2630
      @sagarpatel2630 3 หลายเดือนก่อน

      It happened because files were already moved into folders and if/elif were returning false due to the "and" conditions.

  • @shaaniplays9931
    @shaaniplays9931 ปีที่แล้ว

    Hey alex would you be kind enough to confirm if your data boot camp covers all the basics of those tools so after that i can move on to intermediate stuff. ☺️ Thanks

  • @KarmenKaur-k5h
    @KarmenKaur-k5h 11 หลายเดือนก่อน

    Hi Alex, Could you please tell how can I do this on mac - what will be the path ?
    Thank you.

    • @CaitlinLemon-s6v
      @CaitlinLemon-s6v 11 หลายเดือนก่อน

      Right click on the file and select "get info." However, make sure you've enabled "show path" under "view."

  • @JD_2
    @JD_2 ปีที่แล้ว

    great content

  • @ROZA99090
    @ROZA99090 ปีที่แล้ว +1

    Im not able to make file folders

  • @peterdenes6353
    @peterdenes6353 11 หลายเดือนก่อน

    Hey, great video!
    I am kinda new to programming and I would like to ask for help with two questions if anyone sees this:
    1: When defining the if statement for the for loop, I tried to add multiple formats to a given folder like:
    if ".jpg" or ."png" in file and...( the rest as in the video) but for some reason this made all files and folders copy into the destination directory, which I am not able to understand why?
    2: It worked for me in Jupiter, but I first tried to do it in VS code with an Anaconda virtual environment setup, but for some reason shutil couldn't be accessed. OS worked fine. I have worked with different packages before, so I am not sure why this one doesn't like my virtual environment.
    Thank you for reading all through this and for your help in advance.

    • @nafisansari5854
      @nafisansari5854 9 หลายเดือนก่อน +1

      Hey Man, there are a few issues with the VS code, try using the python terminal in the VS code instead of the Jupyter Notebook extension in it. This could an issue of Code Runner extension. You can go through a few tutorials for Code Runner issue in VS code. Hope this helps.

  • @victoradekunlecom
    @victoradekunlecom ปีที่แล้ว +1

    Also, I had issues doing the amazon web-scrapping project you posted about a year ago because a lot had changed in the webpage source. I asked for help but I didn't get a response, we understand you're busy (we don't your time for granted or feel entitled to it) but do you plan to do another web scrapping project to include in the Free Boot Camp?

    • @jamescao4128
      @jamescao4128 ปีที่แล้ว +1

      What issue u gave, I was able to do it with a different Amazon pahe

    • @jamescao4128
      @jamescao4128 ปีที่แล้ว +1

      *have just shoot me a DM. I'll help you out , I just finished mine yesterday

    • @victoradekunlecom
      @victoradekunlecom ปีที่แล้ว

      @@jamescao4128 Thank you

    • @freemanjavascreen9789
      @freemanjavascreen9789 ปีที่แล้ว

      @@jamescao4128 can you search me up on linnkedn first name and last name.
      Couldn't find you

    • @freemanjavascreen9789
      @freemanjavascreen9789 ปีที่แล้ว

      Victor Adekunle

  • @bufagp648
    @bufagp648 ปีที่แล้ว

    Hi Alex it's not working out is there any other way to do this

  • @rajeshgautam-k2r
    @rajeshgautam-k2r ปีที่แล้ว

    @Alex how do i connect with you?

  • @kaylaesezobor9258
    @kaylaesezobor9258 6 หลายเดือนก่อน

    8:31 mine isn't printinh out anything or making any folder

    • @swethareddy2270
      @swethareddy2270 2 หลายเดือนก่อน

      check wheather the path is crt or not .(path = r"......./" )

  • @garvinasimwe
    @garvinasimwe ปีที่แล้ว +1

    Hi Alex, I am getting an error that says NameError: name 'os' is not defined. Any help is greatly appreciated.

    • @delightogwor3350
      @delightogwor3350 ปีที่แล้ว

      did you pip install os

    • @bufagp648
      @bufagp648 ปีที่แล้ว

      @@delightogwor3350 how do you install os

  • @uplifthabesha754
    @uplifthabesha754 ปีที่แล้ว +2

    Do you think this will be good project to put in our portfolio?

    • @AlexTheAnalyst
      @AlexTheAnalyst  ปีที่แล้ว +1

      I do - it's a pretty neat project :) Something I've used in my job before

  • @thefacelessone74
    @thefacelessone74 7 หลายเดือนก่อน +1

    this video is 12mins of messing up code and 4mins of how to code a automatic file organizer

  • @uchindamiphiri1381
    @uchindamiphiri1381 11 หลายเดือนก่อน

    Suprisingly my fles are not moved

    • @uchindamiphiri1381
      @uchindamiphiri1381 11 หลายเดือนก่อน

      Correction: It has worked after putting two forward slashes on my folder names when operating if statements

  • @davidjukebox
    @davidjukebox ปีที่แล้ว

    I've been going through your videos. This one comes out of nowhere and was painful to watch. What does this have to do with Data Analysis? I didn't follow your work/instructions, was lost within the first section - actually, was lost from a few videos back and have been confused. This could turn into hours of figuring out what you were doing.... and for what?!?! Moving pics around you could have just dragged into a new folder. Insane... why isn't any of this relevant?

  • @economicblast
    @economicblast 10 หลายเดือนก่อน

    bro who codes like this. 😭

  • @peterbelanger4094
    @peterbelanger4094 8 หลายเดือนก่อน

    What is this "jupyter" stuff you are coding on? some online "collab tool?" ..It totally throws me off, why not show us normally, locally, on a command prompt? Some of us do not know or need these cloud based team collab nonsense. We just want t learn Python for ourselves, not in college or some corporate drone.