使用Powershell检测主文件夹中的多个子文件夹
更新: 嗨。如果我的问题听起来含糊不清,我道歉。当我同时运行下面的两个脚本时,ES和LTC子文件夹中的所有csv文件都会保存在一个文件夹中,而不是两个文件夹中。我有两个独立的脚本 监视两个子文件夹LTC和ES,并将文件复制到文件夹中 LTC脚本:使用Powershell检测主文件夹中的多个子文件夹,powershell,powershell-2.0,powershell-3.0,Powershell,Powershell 2.0,Powershell 3.0,更新: 嗨。如果我的问题听起来含糊不清,我道歉。当我同时运行下面的两个脚本时,ES和LTC子文件夹中的所有csv文件都会保存在一个文件夹中,而不是两个文件夹中。我有两个独立的脚本 监视两个子文件夹LTC和ES,并将文件复制到文件夹中 LTC脚本: $folder = 'C:\2014-15' $destination = 'N:\Test' $fsw = New-Object System.IO.FileSystemWatcher $folder -Property @{ Includ
$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
更改为“$destination\ES”
?@arco44,这不起作用。这些是脚本还是您在ISE中运行的命令?我认为我们不理解您的问题。您的手表操作是否工作不正常或是特定的?这只是拥有第二个拷贝目的地的问题吗。LTC代码是否将文件放在错误的目录中?这些是在同一个文件中定义的吗?那么$destination不接受找零吗?@Matt。如果我的问题听起来含糊不清,我道歉。当我同时运行这两个脚本时,ES和LTC子文件夹中的所有csv文件都会在Test1文件夹中结束,而此时它应该是Test中的LTC和Test1文件夹中的ES。
$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
}
}