更新:
您好。如果我的问题听起来很模糊,请道歉。当我在下面同时运行两个脚本时,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
}
}
答案 0 :(得分:0)
$folder = 'C:\2014-15'
$destination = 'N:\Test'
$destination1 = '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 "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
}
}
$fsw = New-Object System.IO.FileSystemWatcher $folder -Property @{
IncludeSubdirectories = $true
NotifyFilter = [IO.NotifyFilters]'DirectoryName'
}
$created = Register-ObjectEvent $fsw -EventName Created -Action {
$item1 = Get-Item $eventArgs.FullPath
If ($item1.Name -ilike "ES") {
Copy-Item "$item1\*.csv" -Destination $destination1
}
}
$created = Register-ObjectEvent $fsw -EventName Created -Action {
$item1 = Get-Item $eventArgs.FullPath
If ($item1.Name -ilike "ES") {
Copy-Item "$item1\*.csv" -Destination $destination1
}
}