r/PowerShell • u/Interesting-Turn2916 • Nov 19 '25
Question Help with folder rename script
Hello, Looking to bulk rename 100s of folders. I have a CSV which contains the full folder name
E.g
C:\dump\folder 1
and next to it what i would like the folder to be renamed, again full folder path rather than just new name
C:\dump\folder renamed
This CSV structure contains multiple sub folders all listed with full folder path rather than just folder name
What would the script be to bulk rename them
CSV titles are old and new
Do i need to ammend so its not full folder path but just folder name for the subfolders etc.
Thanks
4
Upvotes
View all comments
Show parent comment
-1
u/Interesting-Turn2916 Nov 19 '25
Thank you.
I currently have
$csvPath = "C:\CSV\folders.csv"
$logFile = "C:\CSV\rename_log.txt"
"" | Out-File -FilePath $logFile
# Import and sort CSV by folder depth (count of "\")
$folders = Import-Csv -Path $csvPath |
Sort-Object {($_.old -split '\\').Count} -Descending
foreach ($row in $folders) {
$oldFolder = $row.old
$newFolder = $row.new
$logMsg = "Renaming: '$oldFolder' to '$newFolder'"
$logMsg | Out-File -FilePath $logFile -Append
# remove -WhatIf for actual run
Rename-Item -Path $oldFolder -NewName $newFolder -WhatIf
I have organised the CSV so it is arranged by file name length (quick hack to try and do subfolders backwards)