Harry Potter and the Sorcerer's Stone


Katalogni asinxron tarzda o'chirish uchun C# dasturini yozing


Download 192.49 Kb.
bet58/62
Sana17.06.2023
Hajmi192.49 Kb.
#1535967
1   ...   54   55   56   57   58   59   60   61   62
Bog'liq
Algaritim amaliy-2

98. Katalogni asinxron tarzda o'chirish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string catalogName = "catalog_to_delete";
if (Directory.Exists(catalogName))
{
Directory.Delete(catalogName, true);
Console.WriteLine($"Katalog {catalogName} o'chirildi.");
}
else
{
Console.WriteLine($"Katalog {catalogName} mavjud emas.");
}
}
}
99. Katalogni asinxron ko'chirish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string sourceCatalog = "source_catalog";
string destinationCatalog = "destination_catalog";
if (Directory.Exists(sourceCatalog))
{
DirectoryCopy(sourceCatalog, destinationCatalog, true);
Console.WriteLine($"Katalog {sourceCatalog} ko'chirildi {destinationCatalog}");
}
else
{
Console.WriteLine($"Kataloq {sourceCatalog} mavjud emas.");
}
}
static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
DirectoryInfo[] dirs = dir.GetDirectories();

if (!Directory.Exists(destDirName))


{
Directory.CreateDirectory(destDirName);
}

FileInfo[] files = dir.GetFiles();


foreach (FileInfo file in files)
{
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, false);
}

if (copySubDirs)


{
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}
}

Download 192.49 Kb.

Do'stlaringiz bilan baham:
1   ...   54   55   56   57   58   59   60   61   62




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling