在 Windows 中批次重命名文件,以順序產生新名稱

在 Windows 中批次重命名文件,以順序產生新名稱

我需要幫助批量重命名一些文件名。我有大約 300 個目錄。所有文件均為Word.docx文件,重新命名後仍需保留Word文件。

在每個資料夾中,我有 1 到 20 個檔案(絕不超過26)。我需要按某種順序排列它們(最好按當前名稱的字母順序排列)並重命名它們以遵循以下模式:

Example A.docx
Example B.docx
Example C.docx
    etc. 

我無法使用外部軟體,只能使用終端。

答案1

這是一個 PowerShell 腳本,可以滿足您的要求:

$letters = [char[]]([char]'A'..[char]'Z')
$directoryName = $null
$count = 0
Get-ChildItem -Path "your folder path" -File -Recurse | 
  ForEach-Object {
    if ($directoryName -eq $null -or $directoryName -ne $_.DirectoryName) {
      $directoryName = $_.DirectoryName
      $count = 0
  }
  $newname = "Example " + $letters[$count++] + ".docx"
  Rename-Item $_.fullname $newname
}

先備份一下。

相關內容