Created
July 15, 2016 22:28
-
-
Save wilwang/4771a60f427fca97dd8dec3eabbae095 to your computer and use it in GitHub Desktop.
Powershell - Loop through sub directories and look for and rename file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$targDir = "C:\inetpub\websites\ADA*\"; | |
$subDir = $(Get-ChildItem "$targDir"); | |
foreach($sub in $subDir) { | |
$files = $(Get-Childitem $sub -Filter app_offline*.htm); | |
foreach($file in $files) { | |
$oldname = $file.FullName; | |
$newname = $oldname.Replace("_.htm", ".htm"); | |
if ($newname.IndexOf(".htm") -gt 0) { | |
$oldname; | |
$newname; | |
Rename-Item $oldname $newname; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment