Monday, February 28, 2005

C#: files operations

using System.IO;

//create directory:
Directory.CreateDirectory("C:\\testcsharp");
//create subdirectory:
Directory.CreateDirectory("C:\\testcsharp\\dump");
//move:
Directory.Move("C:\\testcsharp\\dump", "C:\\dump");
File.Move( "c:\\gooli.jpg", "c:\\temp\\gooli.jpg");
//delete:
Directory.Delete("C:\\dump");
File.Delete( "c:\\gooli.jpg" );
//copy:
File.Copy( "c:\\gooli.jpg", "c:\\temp\\abc.jpg");
//size of the file:
FileInfo fi = new FileInfo("C:\\gooli.jpg");Console.WriteLine("File size of gooli.jpg: {0}", fi.Length);
//delete a directory recursively:
Directory.Delete("C:\\testcsharp", true);

No comments: