0

Given a folder structure:

---- folder1#name
--------- folder2#name
---- folder3#name
--------- folder4#name
------------ folder5#name
------------ folder6#name
------------ folder7#name

I want to recurisvely go through them and just rename the folders such that I remove the # character from their names.

The reason I want to achieve this is because I am using this structure in my public asset folder for a web project and the # character of course causes issues as it means something else when it comes to URLs.

The easiest thing for me would be if the # did not exist.

How would I achieve this in Windows (I am currently on 10)

6
  • Write a short PowerShell script or use a tool that supports mass renaming folders. For a PS script you will probably need ForEach, Where-Object, Get-ChildItem and Rename-Item.
    – Seth
    Commented Apr 22, 2022 at 6:23
  • Could you point me towards a tool that would help me achieve this?
    – Edd Chang
    Commented Apr 22, 2022 at 6:34
  • I'd just write a script. There are dozens of mass renaming tools. Most focus on files but some probably also support recursive searches, that might be the biggest hurdle.
    – Seth
    Commented Apr 22, 2022 at 6:45
  • Alright. Is there a certain language that would be the most preferrable. If Powershell, could you point me towards any relevant knowledge as I am not much aware with it. If not, that is also ok.
    – Edd Chang
    Commented Apr 22, 2022 at 7:02
  • Have you tried anything to remedy this yourself? As for help you can use Get-Help, Get-Command and Get-Member to discover most of the informaton. about_Foreach and/or ForEach-Object, cut that short previsouly, will also be of interest. As shown in this question you can probably do it with just Get-ChildItem and Rename-Item.
    – Seth
    Commented Apr 22, 2022 at 7:12

3 Answers 3

2

This can be a challenging script to create, so I've taken the liberty to write it for you. It replaces the # by a space. Feel free to change that to anything you want.

# go to the parent folder
set-location -Path C:\temp\test\test#name

#create list and sort it backwards (we want to rename from the deepest folders to the lowest.
$folders = get-childitem -Recurse -Directory |sort-object -Descending

$folders | ForEach-Object {
    set-location $_.parent.FullName
    rename-item $_.name ($_.name -replace("#", " "))
}
1
  • Thanks but I just solved it using a python script
    – Edd Chang
    Commented Apr 22, 2022 at 8:14
1

I ended up using a python script that does the job.

This needs to of course run in the exact folder the os.walk would.... walk?

import os

for root, dirs, files in os.walk(".", topdown=False):
    for name in dirs:
        print("old name: " + name)

        new_name = name.replace('#', '')

        print('new name ' + name)

        os.rename(os.path.join(root, name), os.path.join(root, new_name))
-1

You can use PowerRename in PowerToys:

  1. Download PowerToys
  2. Open PowerToys settings
  3. Activate PowerRename
  4. Do as shown in the GIF on the link below (choose all parent folders, fill in # to be replaced and nothing to replace it): http://norway-yv.epizy.com/files/howto.gif (I swear it is not a virus, but it was "too large" to be embedded in the answer)
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .