簡體   English   中英

在 PowerShell 中重命名文件夾中的文件

[英]Rename Files in a folder in PowerShell

實際上,我已將光標 Powershell 集中在特定文件夾中,但我想重命名該文件夾中包含的所有文件,以便每個文件都像這樣重命名:

文件名.xml.traite => 文件名.xml

確實,我想用空字符串替換“.traite”

這是我會使用的:

Get-ChildItem | Foreach-Object{
    Rename-Item -Path $_.FullName -NewName $_.Name.Replace("traite","")
} 

或者這個,-whatif 用於測試。 大多數您可以通過管道傳遞的任何參數都可以接受腳本塊。 -replace 缺少的第二個參數被假定為空。

Get-ChildItem | Rename-Item -NewName { $_.name -replace '.traite' } -whatif

What if: Performing the operation "Rename File" on target "Item: C:\users\j\foo\filename.xml.traite Destination: C:\users\j\foo\filename.xml".

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM