title: C# - File.Move - Could not find file
body: <p>i have a strange problem with File.Move method.
  Generally I have a service, that monitors for new files appearing on remote share and once they do it changes its extension via &quot;ren&quot; cmd function and calls other service. This other service is then using File.Move to change the extension of the file once again. The problem is that from time to time the second service fails and returns error &quot;Could not find file...&quot; from System.IO.File.InternalMove, while the file is already there.</p>
  <p>Initially I thought that it may be issue with network connection, but I have a feeling that it happens to often to be caused by network problems.</p>
  <p>Next I started digging into .net source code and found something interesting:</p>
  <pre><code>        if (!InternalExists(fullSourceFileName))
               __Error.WinIOError(Win32Native.ERROR_FILE_NOT_FOUND, fullSourceFileName);
          
          if (!Win32Native.MoveFile(fullSourceFileName, fullDestFileName))
          {
              __Error.WinIOError();
          }
  </code></pre>
  <p>This is part of File.InternalMove method which, from my understanding, is returning an &quot;Could not find file...&quot; error. In short InternalExists method is checking if file exists by checking the Marshal.GetLastWin32Error() error and later verifing attributes on file.</p>
  <p>Also what is strange is that it seems that this method is using &quot;hack&quot; of some sort (don't know if it is related to my problem, but it is worrying):</p>
  <pre><code>   // For floppy drives, normally the OS will pop up a dialog saying
              // there is no disk in drive A:, please insert one.  We don't want that.
              // SetErrorMode will let us disable this, but we should set the error
              // mode back, since this may have wide-ranging effects.
              bool success = false;
              int oldMode = Win32Native.SetErrorMode(Win32Native.SEM_FAILCRITICALERRORS);
              try {
                  success = Win32Native.GetFileAttributesEx(path, GetFileExInfoStandard, ref data);
              }
              finally {
                  Win32Native.SetErrorMode(oldMode);
              }
  </code></pre>
  <p>Now the interestring part :)
  Class FileInfo also allows to rename files via MoveTo() method.
  In this method the &quot;moving&quot; part is following:</p>
  <pre><code> if (!Win32Native.MoveFile(FullPath, fullDestFileName))
              __Error.WinIOError();
  </code></pre>
  <p>It is the same as in File class, but it lacks the &quot;InternalExists&quot; verification, so at a glance it looks like it should resolve my problem, but I am little worried about this missing check.</p>
  <p>Does anybody knows why it is implemented like this and if I can use FileInfo.MoveTo method?
  Also if you have any ideas on the cause of the problem, then please share it. Currently I am quessing that when first service is calling &quot;ren&quot; cmd program, the new file isn't fully renamed yet, which causes File.Move method to fail, but I have to yet verify it.</p>