title: End loop after comparing filename and copying it in Vbscript
body: <p>Im am trying to find files in a directory according to a list of numbers. Each file starts with the 6-digit- number but then can end with a random letters. 
  - So i managed it to write a script which compares only the first six letters of the filename.
  Also I only want to copy .pdf and .dxf files 
  -this is why I also check the filetype.</p>
  
  <p>Just to make it more complicated the "Sourcefolder" is different for the files. 
  It consist of the first 3 digits of the number and 2x "_". for example.</p>
  
  <p>C:\files\258__\258956.pdf</p>
  
  <p>This could be solved easily by adding to the sourcepath the first three digits and the __. (But isn't implemented yet)</p>
  
  <p>The problem is my script does run infinitely because it never leaves the loop.
  Also it only checks the first number in the filelist.</p>
  
  <p>I really searched in the Internet prior to this question. Also I would like to give props to the stackoverflow community, cause other questions really helped until now. </p>
  
  <ul>
  <li>I usually only script in vba (Excel) this is why I am unfamiliar with vbs. </li>
  </ul>
  
  <p>Following a part of my filelist which defines which files have to be found</p>
  
  <pre><code>   127287
     257391
     257605
     258956
     261648
     261880
     261886
     262284
  </code></pre>
  
  <p>This is the script I already have</p>
  
  <pre><code>    dim fso, folder, sourcefolder, destfolder, searchname1,fileList
  
      set fso = createobject("scripting.filesystemobject") 
      sourcefolder = "C:\Users\Admin\Desktop\Source"
      destfolder = "C:\Users\Admin\Desktop\output\"
      inputFile = "C:\Users\Admin\Desktop\filelist.txt" 
      Set fileList = fso.OpenTextFile(inputFile, forReading) 
  
      ' Read line after line the next number which has to be found
      searchname1 = fileList.ReadLine() 
  
      ' But stop reading lines if the end is reached
      Do until fileList.AtEndOfStream 
  
      set folder = fso.getfolder(sourcefolder)  
  
      'Compare each file
      for each file in folder.files
          wholefilename = fso.getbasename(file)
          filename = left(wholefilename,6)
          extension = LCase(fso.getextensionName(file))
  
      'first compare the name with the list ¦ then check the fileextenstion 
          if (filename = searchname1) and  ((extension = "pdf") or (extension ="dxf")) then
  
      'it both statements are true, copy the file to the destinationfolder "Ouptut"
  fso.copyfile sourcefolder &amp; "\" &amp; file.name, destfolder
  else          
  end if
  
      next
      Loop
  </code></pre>
  
  <p>The solution to my problem probably is super simple, but I'm really stuck. So any help is appreciated.
  Just to sum up, my big problem is, that the script never exits the loop. 
  But I don't know how and when to end it, after 10'000 loops would be a dumb solution.</p>