我正在嘗試為 PC 上的每個用戶組態檔重命名 \appdata\Roaming\ 中的檔案。我正在嘗試這個命令,但不起作用。我究竟做錯了什么?請幫忙。
$old = 'C:\users\*\AppData\Roaming\SAP\Common\test.txt'
$rename = 'C:\users\*\AppData\Roaming\SAP\Common\test-old.txt'
Get-ChildItem $rename | ForEach-Object {Rename-Item -Path $old -NewName $_ -Force}
uj5u.com熱心網友回復:
我究竟做錯了什么?幾乎所有的東西 ;-)。
請看看這是否滿足您的需求:
$folders = get-childitem 'C:\users\' -directory
foreach ($folder in $folders) {
$file = Join-Path $folder -ChildPath 'AppData\Roaming\SAP\Common\test.txt'
if (Test-Path $file) {
rename-item $file -NewName 'test-old.txt'
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/328447.html
