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