title: How to get script to start over
body: <p>I have this section of code that I need to loop through if the file is locked.
  What I want to do is if the file is locked the script goes to sleep for 10 seconds then goes back to the if (test-Path) and runs through again until the file(s) are no longer locked. 
  I'm just not understanding how to do this, any help is appreciated. </p>
  
  <pre><code>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
  
          }
  </code></pre>