} //end load one CloudCoin from JSON public void MoveFile(string SourcePath, string TargetPath, FileMoveOptions options) { if (!File.Exists(TargetPath)) { File.Move(SourcePath, TargetPath); } else { if (options == FileMoveOptions.Replace) { File.Delete(TargetPath); File.Move(SourcePath, TargetPath); } if (options == FileMoveOptions.Rename) { string targetFileName = Path.GetFileNameWithoutExtension(SourcePath); targetFileName += Utils.RandomString(8).ToLower() + ".stack"; string targetPath = Path.GetDirectoryName(TargetPath) + Path.DirectorySeparatorChar + targetFileName; File.Move(SourcePath, targetPath); } } }
public static void MoveFile([NotNull] string sourceFileName, [NotNull] string destinationFileName, FileMoveOptions fileMoveOptions) { Validate.TryValidateParam <ArgumentInvalidException>(File.Exists(sourceFileName), nameof(sourceFileName), $"File {sourceFileName} does not exist."); for (var retryCount = 0; retryCount < Retries; retryCount++) { try { _ = NativeMethods.MoveFileEx(sourceFileName, destinationFileName, (int)fileMoveOptions); return; } catch (IOException) when(retryCount < Retries - 1) { //RETRY } catch (UnauthorizedAccessException) when(retryCount < Retries - 1) { //RETRY } // If something has a transient lock on the file waiting may resolve the issue Thread.Sleep((retryCount + 1) * 10); } }
public static void MoveFile([NotNull] FileInfo file, [NotNull] FileInfo destinationFile, FileMoveOptions fileMoveOptions = FileMoveOptions.ReplaceExisting) { var fileName = file.ArgumentExists().FullName; fileMoveOptions = fileMoveOptions.ArgumentDefined(); for (var retryCount = 0; retryCount < Retries; retryCount++) { try { _ = NativeMethods.MoveFileEx(fileName, destinationFile.FullName, (int)fileMoveOptions); return; } catch (IOException) when(retryCount < Retries - 1) { //RETRY } catch (UnauthorizedAccessException) when(retryCount < Retries - 1) { //RETRY } // If something has a transient lock on the file waiting may resolve the issue Thread.Sleep((retryCount + 1) * 10); } }