3
我正在嘗試創建一個腳本,它讀取文件的第一行,然後將所有具有類似命名約定的文件移動到一個級別。讀取輸入和移動具有相似名稱的文件
這些都是3個示例文件:
C:\Users\USERNAME\location\PYYYYYYYYY.txt.asc
C:\Users\USERNAME\location\holdingarea\PYYYYYYYYY.tt.asc
C:\Users\USERNAME\location\holdingarea\PYYYYYYYYY.t.asc
劇本我至今是:
$location = Read-Host -Prompt "Location Filename"
$locationfilename = Select-String C:\Users\USERNAME\location\holdingarea\*.txt.asc –pattern $location -Context 1
$locationfilenames = $locationfilename.basename
$locationarea = "C:\Users\USERNAME\location\holdingarea"
$locationlocation = "C:\Users\USERNAME\location"
Select-String C:\Users\USERNAME\location\holdingarea\*.txt.asc -Pattern $location -Context 1 |
Out-File -Append C:\Users\USERNAME\location\logs.txt
Move-Item -Path "$locationfilenames" -Destination "$locationlocation"
加1用於'$ locationlocation' – Naigel
你的腳本有什麼問題? –
它帶回以下錯誤, Move-Item:找不到驅動器。名稱爲'> C'的驅動器不存在。 在行:10字符:10 +移動-項目<<<< -path 「$ paymasterfilenames」 -Destination 「$ paymasterlocation」 + CategoryInfo:ObjectNotFound:(> C:字符串)[移動-項目],DriveNotFoundException + FullyQualifiedErrorId:DriveNotFound,Microsoft.PowerShell.Commands.MoveItemCommand –