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)

Edd Chang
  • 111

3 Answers3

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("#", " ")) }

LPChip
  • 66,193
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))

Edd Chang
  • 111
-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)
yrjarv
  • 613