-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursiveDirectoryRename.ps1
More file actions
25 lines (24 loc) · 1004 Bytes
/
Copy pathRecursiveDirectoryRename.ps1
File metadata and controls
25 lines (24 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$startDate = Get-Date;
$basePath = "[ReplaceMeWithTheStartingPath]"
Write-Host $startDate;
$dirs = gci -Path $basePath | Where-Object {$_.Attributes -eq 'Directory'}
foreach ( $dir in $dirs ) {
Write-Host $dir
$newPath = $basePath + $dir
Set-Location $newPath
$dirPurpleSummaries = gci -Path $newPath -Recurse | Where-Object {$_.Attributes -eq 'Directory' -and $_.Name -eq '[FolderNameToBeReplaced]'}
foreach ( $dirPurpleSummary in $dirPurpleSummaries ) {
Write-Host $dirPurpleSummary
$item = Get-Item $dirPurpleSummary.FullName
$oldpath = $($item.fullname)
$oldname = $($item.fullname | split-path -leaf)
$newname = $($oldname) -replace "[FolderNameToBeReplaced]","[NewFolderName]"
#write-host Checking Path: $oldpath
if (!$oldname.contains($newname)) {
Write-Host Renaming $oldname to $newname;
Rename-Item -Path $oldpath -NewName $newname
}
}
}
$endDate = Get-Date;
Write-Host $endDate