0
我有這段代碼,如果文件被鎖定,我需要循環。 我想要做的是,如果文件被鎖定,腳本進入睡眠狀態10秒鐘,然後返回到if(test-Path)並再次運行,直到文件不再被鎖定。 我只是不理解如何做到這一點,任何幫助表示讚賞。如何讓腳本重新開始
if (Test-Path -Path "$path\*")
{
# Code for directory not empty
# enumerate the items array
foreach ($item in $items)
{
# if the item is NOT a directory, then process it.
if ($item.Attributes -ne "Directory")
{
$filePath = $path+$item.name
}
else
{
}
function isFileLocked([string]$LockedPath)
{
$oFile = New-Object System.IO.FileInfo $LockedPath
# Make sure the path is good
if ((Test-Path -LiteralPath $LockedPath) -eq $false)
{
#If file is locked go to sleep for 2 minutes and check again, loop until the file is no longer locked.
Start-Sleep -s 10
# Go back and check directory again to see if more files have come in
#return $false
}
很好的答案,但我希望看到一個例子。 – TheMadTechnician 2014-09-04 16:47:00
夠公平的。添加示例以幫助 – 2014-09-04 17:18:29
如果可能,我想回到「if(Test-Path -Path」$ path \ *「)」。 – 2014-09-04 19:08:24