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,

Share:
7,002

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    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
      Admin about 10 years
      Could be possible that you end up with directories with the same name? If so, should they be number/ignored/something else?
    • Admin
      Admin about 10 years
      Can you please share the code you've tried so we can see what you're trying to do?
  • Ob1lan
    Ob1lan about 9 years
    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 : superuser.com/tour
  • Jeter-work
    Jeter-work over 8 years
    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'}
  • Admin
    Admin over 8 years
    since the user only wants to rename folders and not files, left of the pipe should read: get-childitem z:/ -Recurse -Directory