Возвращаясь к чему-то более минимальному, это работает без Пока.
$Source = 'E:\Temp\folder\xmls'
$Filter = '*.*'
$destination = 'E:\Temp\Folder\ProcessedXmls'
$Watcher = New-Object IO.FileSystemWatcher $Source, $filter -Property @{
IncludeSubdirectories = $true
NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
}
$onCreated = Register-ObjectEvent $Watcher Created -SourceIdentifier FileCreated -Action {
Start-Sleep -Seconds 3
$Path = $Event.SourceEventArgs.FullPath
Move-Item $Path -Destination $destination -verbose
}
# Results
VERBOSE: Performing the operation "Move File" on target "Item: E:\Temp\folder\xmls\New Text Document.txt Destination: E:\Temp\Folder\ProcessedXmls\New Text Document.txt".
VERBOSE: Performing the operation "Move File" on target "Item: E:\Temp\folder\xmls\New Text Document - Copy.txt Destination: E:\Temp\Folder\ProcessedXmls\New TextDocument - Copy.txt".
VERBOSE: Performing the operation "Move File" on target "Item: E:\Temp\folder\xmls\New Bitmap Image.bmp Destination: E:\Temp\Folder\ProcessedXmls\New Bitmap Image.bmp".
Как и добавление голого минимума, который я мог бы проверить на своем конце.
$Source = 'E:\Temp\folder\xmls'
$Filter = '*.*'
$destination = 'E:\Temp\Folder\ProcessedXmls'
$Watcher = New-Object IO.FileSystemWatcher $Source, $filter -Property @{
IncludeSubdirectories = $true
NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
}
$onCreated = Register-ObjectEvent $Watcher Created -SourceIdentifier FileCreated -Action {
Start-Sleep -Seconds 3
$Path = $Event.SourceEventArgs.FullPath
$date = Get-Date
$logFile = "E:\Temp\folder\Log_" + $date.ToString("yyyyMMdd") + ".txt"
$logline = "$(Get-Date), $changeType, $path"
Add-Content -Path $logFile -Value $logline
Move-Item $Path -Destination $destination -verbose
$logline = "$(Get-Date), File moved to processed folder"
Add-Content -Path $logFile -Value $logline
}
# Log file content --- Log_20190419.txt
04/19/2019 00:40:12, , E:\Temp\folder\xmls\New Text Document.txt
04/19/2019 00:40:12, File moved to processed folder
04/19/2019 00:40:28, , E:\Temp\folder\xmls\New Text Document - Copy.txt
04/19/2019 00:40:28, File moved to processed folder
04/19/2019 00:40:46, , E:\Temp\folder\xmls\New Bitmap Image.bmp
04/19/2019 00:40:46, File moved to processed folder
Кроме того,сон на самом деле не нужен.Конечно, ходы выполняются немедленно, если вы не установили это.