0
我想複製,並將多個文件重命名爲多個文件夾。這些文件夾將按照文件的順序進行標記。例如我需要複製Reports.txt將名稱更改爲Reports_NW01_20120219.txt到一個名爲NW01的文件夾,然後將NW02-NW18的過程相同。文件夾和文件名稱增加1.我是PowerShell的新手,所以請放手。我粘貼了下面的內容。我試圖讀取日期,然後將其附加到文件名。我現在處於完全失落狀態。所以任何幫助表示讚賞:Powershell複製文件腳本
$date = read-host "Enter date of the report YYYYMMDD"
write-host $date
for ($Counter = 1; $Counter -le 1; $Counter++)
{
#Destination for files
$DropDirectory = "C:\Users\dh0520\Documents\Powershell Staging\"
#Current Location of the files
$file = Get-ChildItem -Path "C:\Users\dh0520\Documents\Powershell Test\NW01\Reports.txt"
if ($Counter -lt 10) {
$Destination = $DropDirectory+'NW0' + $Counter
$file = Get-ChildItem -Path "C:\Users\dh0520\Documents\Powershell Test\NW0" + $Counter + "\Reports.txt"
Copy-Item $file.FullName ($Destination + $file.BaseName + "_NW0" + $Counter + "_" + $date +".txt")
}
If ($Counter -ge 10) {
$Destination = $DropDirectory+'NW' + $Counter
$file = Get-ChildItem -Path "C:\Users\dh0520\Documents\Powershell Test\NW" + $Counter + "\Reports.txt"
Copy-Item $file.FullName ($Destination + $file.BaseName + "_NW" + $Counter + "_" + $date +".txt")
}
}
有什麼錯誤訊息/問題? – Raf