Harry Potter and the Sorcerer's Stone


Agar u mavjud bo'lmasa, C# yordamida yangi katalog yarating


Download 192.49 Kb.
bet48/62
Sana17.06.2023
Hajmi192.49 Kb.
#1535967
1   ...   44   45   46   47   48   49   50   51   ...   62
Bog'liq
Algaritim amaliy-2

47. Agar u mavjud bo'lmasa, C# yordamida yangi katalog yarating.
Javob:
string path = @"C:\NewDirectory";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
48. Agar katalog bo'sh bo'lsa, C# yordamida o'chiring.
Javob:
string path = @"C:\NewDirectory";
try
{
if (Directory.Exists(path) && !Directory.EnumerateFileSystemEntries(path).Any())
{
Directory.Delete(path);
}
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
49. Faylni C# yordamida qayta ishlash qutisiga o'tkazing.
Javob:
string path = @"C:\Example\File.txt";
try
{
FileSystem.DeleteFile(path, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
50. C# yordamida qayta ishlash qutisidan faylni tiklang.
Javob:
string path = $"C:\\$RECYCLE.BIN\\S-1-5-21-0123456789-0123456789-0123456789-0123\\Example\\File.txt";
try
{
FileSystem.CopyFile(path, @"C:\Recovered\File.txt");
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
51. C# yordamida qayta ishlash qutisini bo'shating.
Javob:
using Microsoft.VisualBasic.FileIO;
try
{
FileSystem.DeleteDirectory(@"C:\$Recycle.Bin\", UIOption.OnlyErrorDialogs, RecycleOption.DeletePermanently);
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
52. C# yordamida joriy ishchi katalogni o'rnating.
Javob:
string path = @"C:\Example";
Directory.SetCurrentDirectory(path);
53. C# yordamida joriy ishchi katalogni oling.
Javob:
string currentDirectory = Directory.GetCurrentDirectory();
Console.WriteLine(currentDirectory);

Download 192.49 Kb.

Do'stlaringiz bilan baham:
1   ...   44   45   46   47   48   49   50   51   ...   62




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