// Copies a file from one location to another (allows renaming & overwriting destination file) public static void CopyFile(string sourcePath, string destinationPath, bool doOverwrite = false) { destinationPath = destinationPath.Replace('/', '\\'); // If source file exists if (File.Exists(sourcePath)) { // If not overwriting, check if destination file exists if (!doOverwrite && File.Exists(destinationPath)) { // Output warning DebugManager.LogToFile("Attempted to copy file `" + sourcePath + "` to destination `" + destinationPath + "` which already exists. File not copied.", LogType.Warning); } // If overwriting or destination file does not exist else { // Remove filename from destination path string directoryPath = destinationPath.Remove(destinationPath.LastIndexOf('\\')); // If directory does not exist if (!Directory.Exists(directoryPath)) { // Create directory Directory.CreateDirectory(directoryPath); } // Copy source file to destination File.Copy(sourcePath, destinationPath, doOverwrite); } } // If source file does not exist else { // Output warning DebugManager.LogToFile("Attempted to copy missing file `" + sourcePath + "`", LogType.Warning); } }