Merhaba bunun için hazır System.IO altında hazır metodlar var. Mesela şu örneğe bakalım.
// Source: Kaynak klasördür aşağıda yeri belirtilmelidir.
// backupDir:Nereye gideceğidir.
string sourceDir = @"c:\current";
string backupDir = @"c:\archives\2008";
try
{
// Burada klasör içerisinde ki jpg ve txt uzantılı dosyaları dizi içerisine alıyoruz.
string[] picList = Directory.GetFiles(sourceDir, "*.jpg");
string[] txtList = Directory.GetFiles(sourceDir, "*.txt");
// resimleri kopyala
foreach (string f in picList)
{
string fName = f.Substring(sourceDir.Length + 1);
File.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName), true);
}
foreach (string f in txtList)
{
string fName = f.Substring(sourceDir.Length + 1);
try
{
File.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName));
}
catch (IOException copyError)
{
Console.WriteLine(copyError.Message);
}
}
foreach (string f in txtList)
{
File.Delete(f);
}
foreach (string f in picList)
{
File.Delete(f);
}
}
catch (DirectoryNotFoundException dirNotFound)
{
Console.WriteLine(dirNotFound.Message);
}