Skip to content

Instantly share code, notes, and snippets.

@Aravin
Created March 18, 2018 18:07
Show Gist options
  • Save Aravin/a69ff759cc6ed5deec700a99906c45e6 to your computer and use it in GitHub Desktop.
Save Aravin/a69ff759cc6ed5deec700a99906c45e6 to your computer and use it in GitHub Desktop.
Moving 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";
string fullSourcePath = Path.Combine(sourcePath, sourceFileName);
string fullDestPath = Path.Combine(destPath, destFileName);
if (!Directory.Exists(destPath))
Directory.CreateDirectory(destPath);
File.Move(fullSourcePath, fullDestPath, false);
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment