Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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