我感觉到这一点可能相当简单。 基本上,我的申请是,在临时执行期间,产生临时xml文档。 这可能有助于解决问题。 然而,正如刚才所说,它们是临时性的。 它们在一条特定的道路上最多有几秒,然后删除。
我正致力于使客户使用的文字自动化(而不是向他们解释如何建立快速的批量档案)。 下面是我 st的。 应当做的是检查一个目录,等待制作Xml文档。 它将坐下来不断检查,直到档案存在。 之后,它便停止了该 lo,并用复制件将Xml文档复制到新的目录。
我正在努力整合的那部分是,我希望用户能够用钥匙来结束整个文字。 在这个例子中,它留下了 key的钥匙。 理论上说,他们在开始复印程序之后,应当能够随时终止复制(在我所展示的样本代码之前,有人会冒着眼点击科索沃开始。)
然而,现在我还没有能够准确地看到这一点。 “停靠ton子”的编码系统自行运行。 但我如何融合?
第一,工作组:
$key = [System.Windows.Input.Key]::LeftCtrl
Write-Warning "Press the $key to end the copy process."
do {
$isCtrl = [System.Windows.Input.Keyboard]::IsKeyDown($key)
if ($isCtrl) {
Write-Host "`nYou pressed $key. Stopping the copy process." -ForegroundColor Green; break
}
Write-Host "." -NoNewline
Start-Sleep -Milliseconds 200
} while ($true)
As stated, the above works just fine. However, below is my attempt to integrate it. It doesn t work. Once the xml file exists in the directory (this has to happen in order to break out of the first do-until loop, though that could of course be removed for testing purposes), you see the copy actions written (verbose enabled), but when you enable the debugger in Powershell, the script is either still on the copy-item, or has looped back around to it (I am not sure)...
cls
#set key variable and write message on how to end process
$key = [System.Windows.Input.Key]::LeftCtrl
Write-Warning "Press the $key key to end the copy process.`n"
#write waiting for file generation
Write-Host "Waiting for temp files to be generated..`n"
#master loop, copying files until we tell it to stop
do {
#search for new files, but loop doing nothing until they exist
do {
$files = Get-ChildItem $temppath | Where-Object {( New-TimeSpan $_.LastWriteTime).Hours -le 24 }
Start-Sleep -Milliseconds 10
} until ( $files -ne $null )
#copy new files to new directory
Copy-Item $files -Destination $destination -Recurse -Verbose -ErrorAction SilentlyContinue
#look for kill-key
$isCtrl = [System.Windows.Input.Keyboard]::IsKeyDown($key)
if ($isCtrl) {
Write-Host "`nYou pressed $key. Stopping the copy process." -ForegroundColor Green; break
}
} while ( $true )
欢迎任何建议。