Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6561075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:32:33+00:00 2026-05-25T13:32:33+00:00

I often find myself in a situation where I have a folder containing files

  • 0

I often find myself in a situation where I have a folder containing files which are named according to a certain file naming convention, and I have to go through them manually to rename them to the one I want. A laborious repetitive task.

E.g. 01_artist_name_-_album_title_-_song_title_somethingelse.mp3 -> Song_Title.mp3

So the removal of certain bits of information, replacement of underscores with spaces, and capitalisation. Not just for music, that’s just an example.

I have been thinking about automating this task using Python. Basically I want to be able to input the starting convention and my wanted convention and for it to rename them all accordingly.

Ideally I want to be able to do this in Python on Windows, but I have an Ubuntu machine I could use for this if it was easier to do in bash (or Python on UNIX).

If anyone can shed light on how I might approach this problem (suggestion of IO python commands that read contents of a folder – and rename files – on Windows, and how I might go about stripping the information from the filename and categorising it, maybe using RegEx?) I’ll see what I can make it do and update with progress.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:32:34+00:00Added an answer on May 25, 2026 at 1:32 pm

    For your special case:

    import  glob, shutil, os.path
    
    # glob.glob returns a list with all pathes according to the given pattern 
    for path in glob.glob("music_folder/*.mp3"):
    
         # os.path.dirname gives the directory name, here it is "music_folder"
         dirname = os.path.dirname(path)
    
         # example: 01_artist_name_-_album_title_-_song_title_somethingelse.mp3
         # split returns "_song_title_somethingelse.mp3"
         interesting = path.split("-")[2]
    
         # titlepart is a list with ["song", "title"], the beginning "_" and the
         # 'somehting' string is removed by choosing the slice 1:-1
         titlepart = interesting.split("_")[1:-1]
    
         # capitalize converts song -> Song, title -> title
         # join gluest both to "Song_Title"
         new_name = "_".join(p.capitalize() for p in titlepart)+".mp3"
    
         # shutil.move renames the given file
         shutil.move(path, os.path.join(dirname, new_name))
    

    If you want to use regular expression, you have to replace:

         m=re.search(".*-_(\S+_\S+)_.*",path)
         if m is None:
            raise Exception("file name does not match regular expression")
         song_name = m.groups()[0]
         titlepart = song_name.split("_")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often find myself in the following situation. Say I was editing a file
Often I find myself in a situation where I have to deal with catching
I find myself often with a situation where I need to perform an operation
I find myself very often in the situation that I open an element in
I often find myself in a situation where I create a generic interface or
I often find myself removing and adding XML sections in configuration files: tomcat's server.xml
I often find myself using mv to rename a file. E.g. mv app/models/keywords_builder.rb app/models/keywords_generator.rb
I often find myself wanting to compile an example file included in a larger
I find myself in a situation that someone else must have got stuck in
I often find myself in the following situation: The customer reports corrupt data in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.