2014-12-19 105 views
-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 

    } 

} 
+2

更改'$ destination'到' 「$目的地\ ES」'? – arco444 2014-12-19 11:53:38

+0

@ arco44這是行不通的。 – Djbril 2014-12-19 12:24:19

+0

這些腳本,或只是您在ISE中運行的命令? – Eris 2014-12-21 08:58:48

回答

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 

    } 

} 
相關問題