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);
}
}
Do'stlaringiz bilan baham: |