title: vbscript: Constantly check if file(s) exists and display life-time
body: <p>I got a very specific question regarding my code.</p>
  
  <p>So I got a folder. In this folder there can be >=0 files.
  My first script is running in the background, checking if file-count is >0.
  As soon as it is >0, it activates a second script with the path+filename, and as soon as
  a file is deleted/removed from the folder, it displays the lifetime of the file.</p>
  
  <p>Everything works fine, but there is one problem:
  If there are multiple Files in the folder simultaniously, it only "observers" the top one (filename,ascending). So if the first one gets deleted, it sure does observe the second, but the lifetime is wrong because it did not start until the first one got deleted.</p>
  
  <p>Here are my two codes:</p>
  
  <p>Script1.vbs:</p>
  
  <pre><code>Set fso =CreateObject("Scripting.FileSystemObject")
  If WScript.Arguments.Count = 1 Then
      pfadTiff0 = CStr(WScript.Arguments(0))
  Else
      msgbox "Bitte Argumente (Pfade) angeben"
      WScript.Quit
  End If
  
  While True
      Set ordnerTiff0 = fso.GetFolder(pfadTiff0)
      Set filesTiff0 = ordnerTiff0.Files
      anzFilesTiff0 = ordnerTiff0.Files.Count
      If anzFilesTiff0 &gt; 0 Then
          For Each objFile in filesTiff0  
              CreateObject("WScript.Shell").Run "QueueTimeUP.vbs " &amp; objFile.Name &amp; " " &amp; pfadTiff0, 0, True                                      
          Next
      End If
      WScript.Sleep 2000
  WEnd
  </code></pre>
  
  <p>Script2.vbs:</p>
  
  <pre><code>filename = CStr(WScript.Arguments(0))
  pfad = CStr(WScript.Arguments(1))
  Set fso = CreateObject("Scripting.FileSystemObject")
  
  startZeit = Timer()
  komplett = pfad&amp;"\"&amp;filename
  
  While fso.FileExists(komplett) = True
      WScript.Sleep 100
  WEnd
  
  endZeit = Timer()
  differenz = endZeit-startZeit
  msgbox "Existenz von Job " &amp; filename &amp; " in Sekunden: " &amp; differenz
  </code></pre>