Harry Potter and the Sorcerer's Stone


Katalogning zip arxivini asinxron yaratish uchun C# dasturini yozing


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

103. Katalogning zip arxivini asinxron yaratish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
using System.IO.Compression;
class Program
{
static void Main(string[] args)
{
string sourcePath = @"C:\Directory\SubDirectory";
string zipPath = @"C:\Archive.zip";

ZipFile.CreateFromDirectory(sourcePath, zipPath);


Console.WriteLine("Zip archive created successfully.");
}
}
104. Zip arxivini asinxron ravishda chiqarish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
using System.IO.Compression;
class Program
{
static void Main(string[] args)
{
string zipPath = @"C:\Archive.zip";
string extractPath = @"C:\Extracted";

ZipFile.ExtractToDirectory(zipPath, extractPath);

Console.WriteLine("Zip archive extracted successfully.");
}
}
105. Katalog hajmini asinxron olish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
class Program
{
static async Task Main(string[] args)
{
string path = "C:/Example"; // katalog manzili
long size = await GetDirectorySizeAsync(path);
Console.WriteLine($"Katalog hajmi: {size} bayt");
}

static async Task GetDirectorySizeAsync(string path)


{
DirectoryInfo dir = new DirectoryInfo(path);
long size = 0;
FileInfo[] files = await Task.Run(() => dir.GetFiles("*", SearchOption.AllDirectories));
foreach (FileInfo file in files)
{
size += file.Length;
}
return size;
}
}
106. Katalog atributlarini asinxron olish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
class Program
{
static async Task Main(string[] args)
{
string path = "C:/Example"; // katalog manzili
var attributes = await GetDirectoryAttributesAsync(path);
Console.WriteLine($"Katalogning xususiyatlari: {attributes}");
}

static async Task GetDirectoryAttributesAsync(string path)


{
DirectoryInfo dir = new DirectoryInfo(path);
return await Task.Run(() => dir.Attributes);
}
}

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