Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Win10 批次重新命名檔案:PowerShell 腳本一鍵替換關鍵字

編輯:Windows 10 系統介紹

下載的劇集檔名為「浪醫金01、浪醫金02...」,想批次改為「浪漫醫生金師傅01...」。善用 Win10 內建 PowerShell 搭配記事本撰寫腳本,即可秒殺大量檔案重命名,無需安裝額外軟體。

腳本邏輯說明

  • $Path:目標資料夾路徑(固定不變)。
  • $Filter:篩選條件(如 *.mkv 只處理 MKV 檔)。
  • $oldtext:舊關鍵字(如「浪醫金」)。
  • $newtext:新關鍵字(如「浪漫醫生金師傅」)。

核心指令:
Get-ChildItem -Path $Path -Include $Filter | Rename-Item -NewName { $_.Name -replace $oldtext, $newtext }

操作步驟

  1. 開啟記事本,貼上以下腳本並修改四個變數值:
$Path = "D:\Video\Drama"
$Filter = "*.mkv"
$oldtext = "浪醫金"
$newtext = "浪漫醫生金師傅"

Get-ChildItem -Path $Path -Include $Filter | ForEach-Object {
    Rename-Item -Path $_.FullName -NewName ($_.Name -replace $oldtext, $newtext)
}

原始檔名

記事本腳本

  1. 另存為 Rename.ps1(編碼選 UTF-8)。
  2. 在資料夾空白處按 Shift + 右鍵 → 「在這裡開啟 PowerShell 視窗」,輸入 .\Rename.ps1 執行。

PowerShell 優勢: 物件導向管線、支援 .NET、語法易讀,是系統管理員自動化運維神器。日後只需修改變數即可複用。

Copyright © Windows教程網 All Rights Reserved