Mega Code Archive

 
Categories / C# / File Stream
 

File Move Moves a file to a new location

using System; using System.IO; class Test {     public static void Main()     {         string path = @"c:\temp\MyTest.txt";         string path2 = @"c:\temp2\MyTest.txt";         if (!File.Exists(path))         {             using (FileStream fs = File.Create(path)) { }         }         if (File.Exists(path2))             File.Delete(path2);         File.Move(path, path2);         Console.WriteLine("{0} was moved to {1}.", path, path2);         if (File.Exists(path))         {             Console.WriteLine("The original file still exists, which is unexpected.");         }         else         {             Console.WriteLine("The original file no longer exists, which is expected.");         }     } }