我使用生成輸出檔案的軟體,其名稱為:JOB_1_sample-file_20220211083122.txt 在特定檔案夾中。同時有數千個檔案。
文本檔案的開頭是可變的(JOB_1、JOB_2、JOB_3 等)。
示例:JOB_2_sample-file_20220211083122.txt、JOB_34_sample-file_20220211083122.txt、JOB_1007_sample-file_20220211083122.txt。
我需要從檔案中洗掉首字母,只留下“樣本”。最好使用 Powershell、CMD 或 javascript。
有這種可能嗎?
uj5u.com熱心網友回復:
Rename-Item與延遲系結腳本塊一起使用,并結合-replace使用正則運算式洗掉感興趣前綴的操作:
$dir = '.' # specify target dir.
Get-ChildItem -LiteralPath $dir -Filter *.txt |
Rename-Item -NewName { $_.Name -replace '^JOB_\d _' } -WhatIf
注意:上面命令中的-WhatIf常用引數是預覽操作。-WhatIf 一旦您確定該操作將執行您想要的操作,請洗掉。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/428969.html
標籤:javascript 电源外壳 批处理文件 命令
