Recursive folder rename through command line
7,002
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,
Related videos on Youtube
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on September 18, 2022Comments
-
Admin almost 2 years
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
-
Admin about 10 yearsCould be possible that you end up with directories with the same name? If so, should they be number/ignored/something else?
-
Admin about 10 yearsCan you please share the code you've tried so we can see what you're trying to do?
-
-
Ob1lan about 9 yearsWelcome 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 : superuser.com/tour
-
Jeter-work over 8 yearsFiltering 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'}
-
Admin over 8 yearssince the user only wants to rename folders and not files, left of the pipe should read: get-childitem z:/ -Recurse -Directory