Powershell 等待复制过程完成,然后在脚本中继续
我正在一个文件夹中观看活动,当有活动时,我想删除一些其他文件,并从我观看的文件夹中复制新文件和文件夹Powershell 等待复制过程完成,然后在脚本中继续,powershell,Powershell,我正在一个文件夹中观看活动,当有活动时,我想删除一些其他文件,并从我观看的文件夹中复制新文件和文件夹 $watcher = New-Object System.IO.FileSystemWatcher $watcher.Path = "C:\Users\Acer\Desktop\TestSpace\main" $watcher.Filter = "*.*" $watcher.IncludeSubdirectories = $true $watcher.En
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:\Users\Acer\Desktop\TestSpace\main"
$watcher.Filter = "*.*"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
$action = { $path = $Event.SourceEventArgs.FullPath
$changeType = $Event.SourceEventArgs.ChangeType
$logline = "$(Get-Date), $changeType, $path"
Add-content "C:\Users\Acer\Desktop\TestSpace\log.txt" -value $logline
Write-Host "Deleting"
Remove-Item C:\Users\Acer\Desktop\TestSpace\ORA\app\ -Exclude web.config -recurse -force -Confirm:$false
Write-Host "Deleting done"
#Write-Host "Copy"
$copy = (Get-Process (Copy-Item -Path C:\Users\Acer\Desktop\TestSpace\main\app -Exclude web.config -Destination C:\Users\Acer\Desktop\TestSpace\ORA\ -Recurse -verbose))
$copy | Wait-Job
wait-process -id $copy.id
Write-Host "Copy Done"
}
### DECIDE WHICH EVENTS SHOULD BE WATCHED
Register-ObjectEvent $watcher "Created" -Action $action
Register-ObjectEvent $watcher "Changed" -Action $action
Register-ObjectEvent $watcher "Deleted" -Action $action
Register-ObjectEvent $watcher "Renamed" -Action $action
while ($true) {sleep 5}
这很好,但有一个问题,进程只运行了一次,之后仍在等待
Write-Host "Copy"
$copy = (Get-Process (Copy-Item -Path C:\Users\Acer\Desktop\TestSpace\main\app -Exclude web.config -Destination C:\Users\Acer\Desktop\TestSpace\ORA\ -Recurse -verbose))
$copy | Wait-Job
wait-process -id $copy.id
Write-Host "Copy Done"
检查此链接以了解如何使用powershell中的作业
复制项
不能用作获取过程
的输入。你应该在这件事上出错?!