title: Why do FindFirstFile / FindNextFile sometimes see a file on a network folder, but CopyFile does not?
body: <p>I have a function that is supposed to create a backup of a source folder by copying all files from the source to a destination folder. The function uses a while loop driven by <code>FindFirstFile</code> / <code>FindNextFile</code>, then invokes <code>CopyFile</code> for each file found by the <code>Find...</code> function.</p>
  
  <p>Now when the source folder is an SMB network path (regardless of whether I use a mapped drive or a UNC path), it sometimes happens that <code>FindNextFile</code> "sees" a file, but <code>CopyFile</code> refuses to copy the file. The error code is 2, i.e. <code>ERROR_FILE_NOT_FOUND</code>.</p>
  
  <p>I found this hard to believe, so I added a call to <code>_access</code> to the backup function that checks for file existence just before <code>CopyFile</code> is called. The result is the same as for <code>CopyFile</code>, i.e. <code>_access</code> reports that the file does not exist (return code -1 and <code>errno</code> is 2, i.e. <code>ENOENT</code>).</p>
  
  <p>So my main question is: How is it possible that <code>FindFirstFile</code> / <code>FindNextFile</code> "sees" files on a network folder that neither <code>CopyFile</code> nor <code>_access</code> can see?</p>
  
  <p>Additional information / diagnostics:</p>
  
  <ul>
  <li>The problematic file is a file that is created immediately before the backup function is run. Specifically it works like this: A process that runs on the client machine has a network connection to a process that runs on the server machine. The client process tells the server process to create the file. This is supposed to work synchronously: Only after the server process acknowledges that it has created the file does the client process go on to perform the backup.</li>
  <li>I added a retry mechanism to the backup function. With this, <code>CopyFile</code> and<code>_access</code> suddenly start to see the file in question after about 4 seconds of retrying. This indicates to me that there is indeed some sort of network-delay involved. It appears as if <code>FindFirstFile</code> / <code>FindNextFile</code> access the network path differently than <code>CopyFile</code> / <code>_access</code>.</li>
  </ul>
  
  <p>Unfortunately my research to this effect did not turn up any useful information, so I can only speculate. If <code>FindFirstFile</code> / <code>FindNextFile</code> / <code>CopyFile</code> indeed do not work well together, do you know of a different set of find/copy API functions that work more reliable?</p>