Hello,
I’ve got another thread here on matching a value in one array with a value in another array.
The matched value is then stored in a new array, which is then used to serve as the original file/folder name and lined up with another array containing the new names for bulk renaming.
My first test was done against just 5 sample folders, and both arrays were identical in order.
# Match OldName to FullName (matt-bloomfield)
$arrNew = $arrFullNames | Where-Object {
$arrOldNames -contains ($_ | Split-Path -Leaf)
}
However, I’m hesitant on running this same solution against a list of over 1,700 folders. Reason being is that Windows and Excel sort data differently.
$arrOldNames
& $arrNewNames
were matched in Excel and copy/pasted into a text file
$arrFullNames
was created using PowerShell:
# Get ALL Folders (Array List)
$srcPath = '\\mynas\ar_books'
$arrOldNames = New-Object -TypeName System.Collections.ArrayList
$arrOldNames.AddRange(@(Get-ChildItem -Path $srcPath -Directory -Recurse -Force -ErrorAction SilentlyContinue | % { $_.FullName }))
My question:
Am I going about this right way, or is there a better (POSH) way to do the bulk renaming by matching values and then renaming the file/folder without having to create a new array?
For example, I’ll still need to use both Excel and PowerShell to create the values for the arrays due to the contents: Unique book quiz numbers and later some personal media files; movies and shows. So accuracy is critical.
What I’m thinking is that I need to adjust my original method a bit. Instead of creating a new array, perhaps I can just match values in both OldName
and NewName
arrays and then use those two values to rename the file or folder immediately.
The reason for this is just in case the matching winds up being two different indexes:
$arrOldName[23] may be matched to $arrNewName[35]
Any advice to steer me in the right direction would be greatly appreciated.