Recursive folder rename through command line

7

I have 500000 plus files in over 3000 directories and need to rename all folders called PHOTOS to Photos. I also need to Rename any Folders call Photos blah blah blah to be called just Photos. It needs to be recursive to crawl down through our convoluted file struct within a data dump drive z:

Any help appreciated

Jamie

Jinx

Posted 2014-04-22T07:35:11.083

Reputation: 71

2Could be possible that you end up with directories with the same name? If so, should they be number/ignored/something else? – Mixxiphoid – 2014-04-22T08:37:46.027

Can you please share the code you've tried so we can see what you're trying to do? – Dave – 2014-04-22T10:15:24.703

Answers

1

Here is a usefull script to rename your files under the z:/ drive:

Get-ChildItem Z:/ -Recurse | Rename-Item -NewName { $_.name -replace 'PHOTOS', 'Photos'}

Hope this helps.

Regards,

Ob1lan

Posted 2014-04-22T07:35:11.083

Reputation: 1 596

Filtering the list before going to rename will wreak less havoc, take less resources, and run faster: Get-ChildItem M:/ -Recurse | Where-Object { $_.name -like "PHOTOS*"} | Rename-Item -NewName { $_.name -replace 'PHOTOS', 'Photos'} – Xalorous – 2015-11-05T00:42:27.820

since the user only wants to rename folders and not files, left of the pipe should read: get-childitem z:/ -Recurse -Directory – None – 2015-11-30T18:44:08.487

0

Does it needs to be done with powershell ?

On windows, I use the GUI open-source tool called AntRenamer, which should work just fine for your needs.

Keep in mind that windows filesystems are case unsensitive, but case-preserving, you you will probably need to rename PHOTOS to something else like APHOTOS before renaming it to Photos. Otherwise, the system will not detect the change, and refuse to rename it.

MayeulC

Posted 2014-04-22T07:35:11.083

Reputation: 133

Welcome to Super User! On this Q&A site we value answers. Your post is not an answer, but a comment of the original question. Please take this 2 minutes tour to understand how this site works : http://superuser.com/tour

– Ob1lan – 2015-07-06T07:09:50.027