2

I want to batch remove a prefix in folder names so that these folders:

[Folder_2009]Folder0001

[Folder_2009]Folder0002

[Folder_2009]Folder0003

will have folder names like these:

Folder0001

Folder0002

Folder0003

I already found this thread, and while the script works great for files, none works for folders, at least in Windows 10.

I looked around and everything I found was about files and not folders.

Thank you!

Community
  • 1
  • 1
Eman Liame
  • 23
  • 3
  • From what I can see there isn't a command for it. The work around is to move the content to a new folder of the name you want, and then delete the old one. – Aaron Hayman Dec 13 '18 at 10:27
  • Thanks for your response. Unfortunately, I have over 500 folders with the said prefix so doing it one by one is something I'd like to avoid if possible. – Eman Liame Dec 13 '18 at 10:41

1 Answers1

2

In cmd line

for /d %A in ("[*]*") do @for /f "tokens=1* delims=]" %B in ("%A") Do @Echo ren "%A" "%C"

This will only echo then ren command, to execute remove the echo

In a batch file double the percent signs.

Sample output:

> for /d %A in ("[*]*") do @for /f "tokens=1* delims=]" %B in ("%A") Do @Echo ren "%A" "%C"
ren "[Folder_2009]Folder0001" "Folder0001"
ren "[Folder_2009]Folder0002" "Folder0002"
ren "[Folder_2009]Folder0003" "Folder0003"
  • I was under the impression the `ren` didn't work for folders, but I have tested your code and it works for me (although on windows 7) – Aaron Hayman Dec 13 '18 at 11:24
  • Thank you very much! This worked really well. – Eman Liame Dec 13 '18 at 11:26
  • 3
    @AaronHayman The help `ren /?` is a bit short and ambiguous in that point. For more details read https://ss64.com/nt/ren.html –  Dec 13 '18 at 11:34