public static bool Rename(string path1, string path2) { if (string.Equals(path1, path2, StringComparison.InvariantCultureIgnoreCase)) { return(true); } if (File.Exists(path2)) { using (CopyDialog dialog = new CopyDialog(path2, path1) { Text = "Move" }) { DialogResult r = dialog.ShowDialog(); if (r == DialogResult.Yes) { File.Delete(path2); } else { return(false); } } } File.Move(path1, path2); return(true); }
public static bool Copy(string path1, string path2, bool deleteFirst = false, bool confirmOverwrite = true) { if (File.Exists(path2) && confirmOverwrite) { using (CopyDialog dialog = new CopyDialog(path2, path1) { Text = "Copy" }) { DialogResult r = dialog.ShowDialog(); if (r != DialogResult.Yes) { return(false); } } } string dir = Path.GetDirectoryName(path2); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (deleteFirst) { File.Delete(path2); } File.Copy(path1, path2, true); return(true); }