Powershell从文件名中删除时间戳

rsc*_*rin 1 powershell

如果我有一些名为 pippo_yyyymmdd.txt、pluto_yyyymmdd.txt 等的文件,如何删除时间戳并将文件重命名为 pippo.txt、pluto.txt ?

Sha*_*evy 5

尝试一下,它会删除所有下划线后跟 8 位数字。这是 basicmidea,它不处理最终具有相同名称的文件:

Get-ChildItem *.txt | 
Where {$_.Name -match '_\d{8}\.txt' } | 
Rename-Item -NewName {$_.Name -replace '_\d{8}'}
Run Code Online (Sandbox Code Playgroud)