Created
March 18, 2018 18:04
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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