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

  • SEARCH
  • Home
  • 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 6010651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:08:48+00:00 2026-05-23T02:08:48+00:00

I need a super simple script that changes the names of the subfolders of

  • 0

I need a super simple script that changes the names of the subfolders of the actual folder

Here’s a little example for better understanding.
Im in the folder My Music and I want to change tha name of all the subfolders (This_Is_A_Example_Subpath):

C:/My Music/This_Is_A_Example_- Subpath
C:/My Music/This_Is_A_Example_- Subpath1
C:/My Music/This_Is_A_Example_- Subpath2

I want to change to:

C:/My Music/This Is – A Example – Subpath
C:/My Music/This Is – A Example – Subpath1
C:/My Music/This Is – A Example – Subpath2

  • 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-23T02:08:49+00:00Added an answer on May 23, 2026 at 2:08 am
    import os
    import os.path
    
    for (dirpath, dirnames, filenames) in os.walk('C:/My Music/'):
        for idx in range(len(dirnames)):
            newname = dirnames[idx].replace('_', ' ')
            os.rename(os.path.join(dirpath, dirnames[idx]), os.path.join(dirpath, newname))
            dirnames[idx] = newname
    

    A bit of an explanation here. This walks through all of the subdirectories using os.walk. However since you’re changing the name of the directory as you’re traversing the tree, you need to update the directory names that it’s going to walk. So this (1) renames the directory, and (2) updates the list so that it walks the newly-named directories.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made a simple bash script that need to keep it's super-user privileges throughout
I need a super-readable version of this super simple inheritance in JavaScript. This is
I have a web service that returns a super simple list of objects MyObject[]
I've written a super simple java class that is throwing exceptions as it should.
I'm doing a little user/password emulator with a super simple visual interface (using Tkinter)
I need an extra pair of eyes! I have a super-simple query: $result =
I bet this is super simple and easy but can't find a basic example
i need a regex that converts commas to spaces. I know this is super
all i need is a very simple auto complete that suggests words that have
I'm looking for a super simple jQuery extension. Basically I need to use some

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.