简体   繁体   中英

how can i recursively rename folders in windows matching string and ignoring case

I have subfolders which have names:

  • original_Optimize
  • Original_optimize
  • original_optimize
  • Original_Optimize

I would like to rename all of these to:

  • Original_Optimize

Is there an easy way of doing this in windows (perhaps using powershell or something in command prompt ) ?

You can do that in two Rename-Item calls. The first would add a prefix to each name to avoid the 'Source and destination path must be different.' error. The second run will remove the prefix.

Get-ChildItem -Filter original_optimize -Recurse | 
Rename-Item -NewName __foo__Original_Optimize -PassThru | 
Rename-Item -NewName {$_.Name -replace '^__foo__'} -PassThru

试试这个。

Get-ChildItem C:\path-to-directory -Recurse -Filter *foo* | Rename-Item -NewName { $_.name -replace 'foo', 'bar'} -verbose

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM