Python Tutorial: Automate Parsing and Renaming of Multiple Files

///Python Tutorial: Automate Parsing and Renaming of Multiple Files

Python Tutorial: Automate Parsing and Renaming of Multiple Files

FavoriteLoadingAdd to favorites

In this video we will be writing a quick script to automate the parsing and renaming of multiple files. Writing quick scripts to automate boring and repetitive tasks is a great way to learn Python and it is a great way to save time. Let’s get started.

The code from this video can be found at:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –

#Python

source

By |2019-12-12T00:31:05+00:00December 12th, 2019|Python Video Tutorials|41 Comments

41 Comments

  1. Kapil Saxena December 12, 2019 at 12:31 am - Reply

    Great work, but when I try it it worked for around half of the files?

  2. Zhiheng Dong December 12, 2019 at 12:31 am - Reply

    How about .split(" – ") :3

  3. Mark Lidnov December 12, 2019 at 12:31 am - Reply

    Traceback (most recent call last):

    File "D:rename.py", line 20, in <module>

    f_title, f_course, f_number = file_name.split('-')

    ValueError: not enough values to unpack (expected 3, got 1)

    [Finished in 0.1s]+

  4. jankhan1000 December 12, 2019 at 12:31 am - Reply

    Superb tutor ……… thanks Sir, love u

  5. Jagadish S December 12, 2019 at 12:31 am - Reply

    Awesome sir

  6. Soumya Ranjan Das December 12, 2019 at 12:31 am - Reply

    Thank you Corey for your time and effort. Keep spreading the knowledge.

  7. Dhwanil Bhatt December 12, 2019 at 12:31 am - Reply

    Hi Corey,
    Thanks for these videos. They are really helpful for a beginner like me.
    I am practicing all the exercises you are sharing in these videos.
    I need little help here,
    I just tried this exercise of renaming multiple files, but it is showing an error:
    Below is the code:
    —————————————————-
    mydir = input('Input the path of directory: ')

    all_files = os.listdir(mydir)

    for f in all_files:

    print(f)

    f_name, f_ext = os.path.splitext(f)

    f_dex = f_name[-3:]

    new_name = 'DEX_{}{}'.format(f_dex,f_ext)

    os.rename(f, new_name)

    print(f)
    ———————————————————————
    below is the error:
    FileNotFoundError: [WinError 2] The system cannot find the file specified: 'ABC_XYZ.DAT' -> 'DEX_XYZ.DAT'

    —————————————————————————
    For path directory i tried with both forward(/) and backward() slash but no success.

    I would really appreciate your help.

    Thanks in advance:)

  8. C. Johnson December 12, 2019 at 12:31 am - Reply

    WOW!!!! You have explained this in an amazingly easy to understand manner. If I didn't already have a son I would have named my first born after you! But really, this was super helpful. THANK YOU

  9. khalid HASSANI December 12, 2019 at 12:31 am - Reply

    now i need another tutorial to build a programme that adds this diez simbol

  10. khalid HASSANI December 12, 2019 at 12:31 am - Reply

    Welcome to data computer science

  11. Tomas Mecius December 12, 2019 at 12:31 am - Reply

    Loved it! Gonna use it

  12. Linda Phan December 12, 2019 at 12:31 am - Reply

    You are the best!

  13. Victor Olet December 12, 2019 at 12:31 am - Reply

    Corey, this is great! This is something I face often and one of the reasons I wanted to learn Python (Coding).
    Please do more videos like this!

  14. Muddather Abuzaid December 12, 2019 at 12:31 am - Reply

    Alslamu Alikum Corey.. i certainly love this tutorial and sure please make a video like this one from time to time. i was thinking about how to automatically name files in a certain directory based on the existing files names by adding the id number like this so you can imagine how helpful this tutorial would be for me specially while i was just reading about os and pathlib before finding this video in my recommendations. so again thank you and i wish you all the best en shaa Allah.

  15. Aaron Agnew-Griffith December 12, 2019 at 12:31 am - Reply

    This was exactly what I was looking for, as a newbie in Python, I have hundreds of pictures saved from old mobiles, cameras etc and stored on a hard drive. Have been putting off tidying them and sorting them for almost 3 years, but thanks to your great tutorial, this will save me hours if not days of work. Thank you and please post more of these helpful videos, for us Newbies learning Python, who don't want to watch "Learn to code Python, length of video 9 hours" !!! just to spend the first 5 hours downloading and customising our IDE and type "Hello World" . We want quick easy practical get your hands dirty type vidoes that last no more then 5 to 15 mins, because our attention span is limited due to the magpie effect of shiny things distracting us. Thanks again.

  16. 231doughboy December 12, 2019 at 12:31 am - Reply

    Do you have any other videos like this where you automate tasks like this?

  17. James Clark December 12, 2019 at 12:31 am - Reply

    Excellent tutorial!

  18. Aspire Tutorials December 12, 2019 at 12:31 am - Reply

    I ran into the very same problem today. Thanks a lot for the great video.

  19. serdar kuyuk December 12, 2019 at 12:31 am - Reply

    I definitely want these types of videos. Thank you

  20. satish kumar December 12, 2019 at 12:31 am - Reply

    I am disappointed with you forget to include Moon in to ur list 😀

  21. Andy N December 12, 2019 at 12:31 am - Reply

    THIS IS MIND BLOWING AND SUPER COOL STUFF COREY!

  22. Mhamad Kassem December 12, 2019 at 12:31 am - Reply

    You are the best man!! Keep it👌🏻👌🏻

  23. Nick S December 12, 2019 at 12:31 am - Reply

    FYI, I got an error using this same approach. I was opening a .csv file though. It didn't like multiple variables (ValueError: too many values to unpack (expected 3)). It worked fine when I used one variable and called as a list: print("{}-{}-{}{}".format(var[0], var[1], var[2])

  24. Nick S December 12, 2019 at 12:31 am - Reply

    zfill, didn't know that one. 🔥

  25. juan alvarado December 12, 2019 at 12:31 am - Reply

    Just wow…

  26. 231doughboy December 12, 2019 at 12:31 am - Reply

    I was able to follow along what he was doing, but I don't get how the files automatically sorted themselves in numerical order — how did it do that without writing specific code?

  27. Maajid Khan December 12, 2019 at 12:31 am - Reply

    Just Subscribe this channel, too good!!

  28. huyen yen December 12, 2019 at 12:31 am - Reply

    love from Vietnam :))

  29. IT Guy December 12, 2019 at 12:31 am - Reply

    Your Python videos are very clear and efficient easy to understand, no confusion. Better than other people's. Very helpful.

  30. J P December 12, 2019 at 12:31 am - Reply

    Superb explanation

  31. Pawel S December 12, 2019 at 12:31 am - Reply

    Dude , big thanks 👍🏻

  32. Chuck Scott December 12, 2019 at 12:31 am - Reply

    Thank you! This was my first experience with any scripiting and I was able to understand and apply what you showed in this video. Thanks for making Python not the hardest thing I've tried to learn.

  33. Jonathan Villafana December 12, 2019 at 12:31 am - Reply

    Great video on scripting and debug tips! More videos like this on automating repetitive tasks 🙂

  34. Eric Lambert December 12, 2019 at 12:31 am - Reply

    Please do more like this – the real world application and step-by-step process to create the solution is invaluable! Great stuff. Thanks.

  35. Shivam Bhirud December 12, 2019 at 12:31 am - Reply

    Why does those videos aren't appearing in the sequence as that in the actual file? How can we make the code read them sequentially?

  36. Matthew O'Connell December 12, 2019 at 12:31 am - Reply

    Really informative. I’m new to python and it’s helpful to see some examples like this

  37. Arun Kumar December 12, 2019 at 12:31 am - Reply

    Superb 😊😊

  38. Arif zafar December 12, 2019 at 12:31 am - Reply

    python with orgasim

  39. James Edmondson December 12, 2019 at 12:31 am - Reply

    You are awesome! Very well done tutorial, super helpful 🙂

  40. jay l December 12, 2019 at 12:31 am - Reply

    I actually wrote my first script on this. I am debugging but it does work. Great vid

  41. Ajitesh Sinha December 12, 2019 at 12:31 am - Reply

    The first thing I did immediately after watching the video is LIKE it….really nice video tells us how we can use python in our day to day life. Make more of these kind of videos.

Leave A Comment

*