Advertisement
Computermaster

Untitled

Feb 11th, 2019
647
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $originalFilesDirectory = "C:\your\directory\here"
  2. $files = Get-ChildItem -Path $originalFilesDirectory | Where-Object { $_.Name -notmatch "Renamed" }
  3. $renamedFilesDirectory = $originalFilesDirectory + "\Renamed"
  4.  
  5. if (!(Test-Path $renamedFilesDirectory)) { New-Item -Path $renamedFilesDirectory -ItemType Directory }
  6.  
  7.     foreach ($file in $files) {
  8.         Write-Host "You are about to rename $file"
  9.         $newName = Read-Host "What would you like to rename this file to?"
  10.         try {
  11.             Copy-Item -Path $file.FullName -Destination "$renamedFilesDirectory\$newName$($file.Extension)" -ErrorAction Stop
  12.             Rename-Item -Path $file.FullName -NewName "$($file.Name).Renamed"
  13.             Write-Host "Rename Successful" -ForegroundColor Green
  14.         }
  15.         catch { Write-Host "Rename Failed: $($_.Exception.Message)" -ForegroundColor Red }
  16.         Write-Host
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement