Created
March 18, 2018 18:07
-
-
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
This file contains 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"; | |
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