Directory sinfidan foydalanish Directory sinfining metodlari va ular bilan ishlash 6


Download 0.55 Mb.
bet7/14
Sana28.12.2022
Hajmi0.55 Mb.
#1013966
1   2   3   4   5   6   7   8   9   10   ...   14
Bog'liq
Dasturlash asoslari fanidan C# dasturlash tilining Directory,

Foydalanish misoli:
using System;
using System.IO;
namespace Dir
{
class Program
{
public static void Main(string[] args)
{
string root = @"C:\Temp";
// katalogning oxirgi yozilish vaqtini belgilash va olish
Directory.SetLastWriteTime(root, DateTime.Now);
DateTime lastWriteTime =Directory.GetLastWriteTime(root);
Console.WriteLine("So'nggi yozish sanasi va vaqti:
"+lastWriteTime);
Console.ReadKey(true);
}
}
}
Natijasi:

GetCurrentDirectory() – ilovaning joriy ishchi katalogini oladi.
SetCurrentDirectory(String) – belgilangan katalogni joriy katalog sifatida o'rnatadi.
Foydalanish misoli:
using System;
using System.IO;
namespace Dir
{
class Program
{
public static void Main(string[] args)
{
string root = @"C:\Windows";
Directory.SetCurrentDirectory(root);
Console.WriteLine(Directory.GetCurrentDirectory());
Console.ReadKey(true);
}
}
}
Natijasi:

GetDirectories(String) – belgilangan katalogdagi pastki kataloglarning nomlarini (shu jumladan yo’llarini) qaytaradi.
Foydalanish misoli:
using System;
using System.IO;
namespace dir
{
class Program
{
public static void Main(string[] args)
{
var docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string[] myDirs = Directory.GetDirectories(docPath);
Console.WriteLine("Kataloglar:");
foreach (var myDir in myDirs)
{
Console.WriteLine(myDir);
}
Console.ReadKey(true);
}
}
}
Natijasi:

GetDirectories(String, String) – belgilangan katalogdagi qidiruv uslubiga mos keladigan pastki kataloglarning nomlarini (shu jumladan yo’llarini) qaytaradi.
GetDirectories(String, String, SearchOption) – belgilangan katalogdagi belgilangan qidiruv namunasiga mos keladigan pastki kataloglarning nomlarini (shu jumladan yo’llarini) va ixtiyoriy ravishda pastki kataloglarni qaytaradi.

Download 0.55 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10   ...   14




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