Directory sinfidan foydalanish Directory sinfining metodlari va ular bilan ishlash 6


Download 0.55 Mb.
bet11/14
Sana28.12.2022
Hajmi0.55 Mb.
#1013966
1   ...   6   7   8   9   10   11   12   13   14
Bog'liq
Dasturlash asoslari fanidan C# dasturlash tilining Directory,

Foydalanish misoli:
DirectoryInfo di = new DirectoryInfo(@"C:\TempDir");
if (di.Exists == false)
di.Create();
DirectoryInfo dis = di.CreateSubdirectory("SubDir");
Console.WriteLine("Katalog va pastki katalog muvafaqqiyatli yaratildi.");
//True shuni ko'rsatadiki, agar ushbu katalogda pastki kataloglar
// yoki fayllar bo'lsa, ular ham o'chiriladi.
di.Delete(true);
Console.WriteLine("Katalog va pastki katalog muvafaqqiyatli o'chirildi.");
Console.ReadKey();
Natijasi:
GetDirectories() – belgilangan katalogdagi pastki kataloglarning nomlarini (shu jumladan yo’llarini) qaytaradi.
Foydalanish misoli:
using System;
using System.IO;
public class GetDirectoriesTest 
{
public static void Main() 
{
DirectoryInfo di = new DirectoryInfo("C:\\");
DirectoryInfo[] diArr = di.GetDirectories();
Console.Write(" 'C:\\' diskdagi kataloglar:");
Console.WriteLine();
foreach (DirectoryInfo dri in diArr)
Console.WriteLine("\t" +dri.Name);
Console.ReadKey();
}
}
Natijasi:

GetDirectories(String) – belgilangan katalogdagi qidiruv uslubiga mos keladigan pastki kataloglarning nomlarini (shu jumladan yo’llarini) qaytaradi.
GetDirectories(String, SearchOption) – belgilangan katalogdagi belgilangan qidiruv namunasiga mos keladigan pastki kataloglarning nomlarini (shu jumladan yo’llarini) va ixtiyoriy ravishda pastki kataloglarni qaytaradi.
Foydalanish misoli:
using System;
using System.IO;
public class GetDirectoriesTest 
{
public static void Main() 
{
DirectoryInfo di = new DirectoryInfo("C:\\");
DirectoryInfo[] diArr = di.GetDirectories("p*"); //("p*", SearchOption.TopDirectoryOnly)
Console.Write(" 'C:\\' diskdagi 'p' harfi bilan boshlanuvchi kataloglar:");
Console.WriteLine();

Download 0.55 Mb.

Do'stlaringiz bilan baham:
1   ...   6   7   8   9   10   11   12   13   14




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