APrettyCoolProgram
12/17/2019 - 4:16 PM

Files

FileCopy.cs

  • FileCopy.cs
  • FileCopyDoNotOverwrite.cs
  • FileCopyWithTimestamp
// Copy a file from a source to a destination.
public static void FileCopy(string sourcePath, string destinationPath)
{
    if (File.Exists(sourcePath))
        File.Copy(sourcePath, destinationPath);
}

// Copy a file from a source to a destination, and do not overwrite any existing files.
public static void FileCopyDoNotOverwrite(string sourcePath, string destinationPath)
{
    if (File.Exists(sourcePath)  && !File.Exists(destinationPath))
        File.Copy(sourcePath, destinationPath;
}

// Copy a file from a source to a destination, and append a timestamp
public static void FileCopyWithTimestamp(string sourcePath, string destinationPath)
{
    if (File.Exists(sourcePath))
        File.Copy(sourcePath, destinationPath + "-" + DateTime.Now.ToString("yyMMdd-HHmmss");
}