/// <summary> /// Move a file from a folder to a new one. /// </summary> /// <param name="existingFileName">The original file name.</param> /// <param name="newFileName">The new file name.</param> /// <param name="flags">Flags about how to move the files.</param> /// <returns>indicates whether the file was moved.</returns> public static bool MoveFile(string existingFileName, string newFileName, MoveFileFlag flags) { int retries = 10; while (retries > 0) { try { return(NativeMethods.MoveFileEx(existingFileName, newFileName, flags)); } catch (Exception) { retries--; if (retries <= 0) { throw; // giving up and report error } // yield control to other threads so that we get a little // wait before we retry. Thread.Sleep(msecsBetweenRetries); continue; } } //while return(false); }
internal static extern bool MoveFileEx( string lpExistingFileName, string lpNewFileName, MoveFileFlag dwFlags);
public static bool MoveFile(string existingFileName, string newFileName, MoveFileFlag flags) { return(MoveFileEx(existingFileName, newFileName, (int)flags)); }