在我的桌面上更改测试文件夹后,脚本会执行某些操作。
例如
如果我将一些带有子文件夹的文件夹复制到我的测试文件夹中。我想这个脚本会一直等到外部复制完成,之后脚本会继续。
此脚本是我文件夹的观察者。
#<Set Path to be monitored>#
$searchPath = "C:\Users\Desktop\test"
#<Set Watch routine>#
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = $searchPath
$watcher.IncludeSubdirectories = $false
$watcher.EnableRaisingEvents = $true
#<Set Events>#
$created = Register-ObjectEvent $watcher "Created" -Action {
Write-EventLog Application -source Powershell -EventId 54321 -Message "Application will be update"
write-host "Application will be update $($eventArgs.FullPath)"
#something what will be wait until copying will
done and after that will script continue
Start-Process powershell -argument '.\done.ps1'
}
while ($true){ sleep 2}
#<END_SCRIPT>#