Skip to content

Instantly share code, notes, and snippets.

@wilwang
Created July 15, 2016 22:28
Show Gist options
  • Save wilwang/4771a60f427fca97dd8dec3eabbae095 to your computer and use it in GitHub Desktop.
Save wilwang/4771a60f427fca97dd8dec3eabbae095 to your computer and use it in GitHub Desktop.
Powershell - Loop through sub directories and look for and rename file
$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