-1
已更新:使用Powershell檢測主文件夾內的多個子文件夾
嗨。道歉,如果我的問題聽起來含糊不清。當我將下面的兩個腳本一起運行時,所有來自ES和LTC子文件夾的csv文件都將在一個文件夾中而不是兩個文件夾中。我有兩個單獨的腳本 來監視兩個子文件夾LTC和ES並將文件複製到文件夾。
LTC腳本:
$folder = 'C:\2014-15'
$destination = 'N:\Test'
$fsw = New-Object System.IO.FileSystemWatcher $folder -Property @{
IncludeSubdirectories = $true
NotifyFilter = [IO.NotifyFilters]'DirectoryName'
}
$created = Register-ObjectEvent $fsw -EventName Created -Action {
$item = Get-Item $eventArgs.FullPath
If ($item.Name -ilike "LTC") {
Copy-Item -Path $folder -Destination $destination
}
}
$renamed = Register-ObjectEvent $fsw -EventName Renamed -Action {
$item = Get-Item $eventArgs.FullPath
If ($item.Name -ilike "LTC") {
Copy-Item -Path $folder -Destination $destination
}
}
ES腳本:
$folder = 'C:\2014-15'
$destination = 'N:\Test1'
$fsw = New-Object System.IO.FileSystemWatcher $folder -Property @{
IncludeSubdirectories = $true
NotifyFilter = [IO.NotifyFilters]'DirectoryName'
}
$created = Register-ObjectEvent $fsw -EventName Created -Action {
$item = Get-Item $eventArgs.FullPath
If ($item.Name -ilike "ES") {
Copy-Item "$item\*.csv" -Destination $destination
}
}
$created = Register-ObjectEvent $fsw -EventName Created -Action {
$item = Get-Item $eventArgs.FullPath
If ($item.Name -ilike "ES") {
Copy-Item "$item\*.csv" -Destination $destination
}
}
更改'$ destination'到' 「$目的地\ ES」'? – arco444 2014-12-19 11:53:38
@ arco44這是行不通的。 – Djbril 2014-12-19 12:24:19
這些腳本,或只是您在ISE中運行的命令? – Eris 2014-12-21 08:58:48