Skip to content

Instantly share code, notes, and snippets.

@Aravin
Created March 18, 2018 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aravin/e3fcad36a44162bcf7509fda2c8eb3a5 to your computer and use it in GitHub Desktop.
Save Aravin/e3fcad36a44162bcf7509fda2c8eb3a5 to your computer and use it in GitHub Desktop.
Copying file from one destination to another destination in C# using System.IO.File Class
using System;
using System.IO;
namespace FileMovement
{
class Program
{
static void Main(string[] args)
{
string sourcePath = @"G:\Learning\CSharp\FileMovement\FileMovement\";
string destPath = @"G:\Learning\CSharp\FileMovement\FileMovement\Archive\";
string sourceFileName = "file.txt";
string destFileName = DateTime.Now.ToString("ddMMMyy-hhmmss") + ".txt"; // for filename with timestamp
string fullSourcePath = Path.Combine(sourcePath, sourceFileName);
string fullDestPath = Path.Combine(destPath, destFileName);
if (!Directory.Exists(destPath))
Directory.CreateDirectory(destPath);
File.Copy(fullSourcePath, fullDestPath, false);
File.Delete(fullSourcePath);
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment