
我正在嘗試編寫一個 PowerShell 腳本來執行以下操作。
步驟1
根據來源檔案“Source_list.csv”,使用“current_name_datetime.csv”重新命名來源(FTP 資料夾)目錄中的文件,該檔案具有目錄“source,destination”,我希望此腳本進行研究。
第2步
根據 Source_list.csv 中的目標將新重命名的檔案複製到備份目錄,該檔案具有我希望此腳本查看的目錄「來源,目標」。
步驟3
將新重命名的檔案移到不在我目前腳本中的最終目標目錄。
----------------------我的腳本 ----------------------
$sdfiles = Get-Content c:\!tony\Source_list.csv
$sourceDir = "c:\test\"
$destinationDir = "c:\testing\"
Get-ChildItem $sourceDir -Recurse -Include $sdfiles "*.csv"|
ForEach-Object{
$newname= "{0}{1}_{2}.csv" -f $destinationDir, $_.BaseName,[datetime]::Now.ToString('MM-dd-yyyy-hh-mm-ss')
$_|Copy-Item -Include ,$sfiles -Destination $newname -whatif }
- - - - - - - - - - - -錯誤 - - - - - - - - - - - - -
What if: Performing operation "Copy Directory" on Target "Item: C:\test\cscenter Destination: C:\testing\cscenter_10-01-2015-12-22-24.csv".
我在錯誤中看到它正在嘗試複製目錄而不是每個目錄中的單個文件,並使用原始文件夾名稱創建一個新文件夾並重命名該文件夾並附加日期/時間戳。
任何幫助將不勝感激。