C# da mavjud faylga matnni qanday qo'shish mumkin?


C# yordamida faylning oxirgi yozish vaqtini oling


Download 22.09 Kb.
bet2/3
Sana17.06.2023
Hajmi22.09 Kb.
#1526406
1   2   3
Bog'liq
Azizbek

9. C# yordamida faylning oxirgi yozish vaqtini oling
using System;
using System.IO;

class Program


{
static void Main(string[] args)
{
// Fayl nomi
string fileName = "example.txt";

// Faylni yaratish va yozish


using (StreamWriter writer = File.CreateText(fileName))
{
writer.WriteLine("Hello, world!");
}

// Faylning oxirgi yozish vaqti


DateTime lastWriteTime = File.GetLastWriteTime(fileName);

Console.WriteLine("Faylning oxirgi yozish vaqti: " + lastWriteTime);


}
}
39. C# yordamida fayl yoki katalog yaratish vaqtini belgilang
using System;
using System.IO;

class Program


{
static void Main(string[] args)
{
// Fayl nomi
string fileName = "example.txt";

// Faylni yaratish va yozish


using (StreamWriter writer = File.CreateText(fileName))
{
writer.WriteLine("Hello, world!");
}

// Fayl yaratilgan vaqti


DateTime creationTime = File.GetCreationTime(fileName);

Console.WriteLine("Fayl yaratilgan vaqti: " + creationTime);

// Katalog nomi
string directoryName = "example_directory";

// Katalogni yaratish


Directory.CreateDirectory(directoryName);

// Katalog yaratilgan vaqti


creationTime = Directory.GetCreationTime(directoryName);

Console.WriteLine("Katalog yaratilgan vaqti: " + creationTime);


}
}
69. Faylni bir katalogdan boshqasiga o'tkazish uchun C# dasturini yozing.
using System;
using System.IO;

class Program


{
static void Main(string[] args)
{
// Fayl nomi va joriy joylashgan manzil
string fileName = "example.txt";
string sourcePath = @"C:\temp";

// Faylni yaratish va yozish


using (StreamWriter writer = File.CreateText(Path.Combine(sourcePath, fileName)))
{
writer.WriteLine("Hello, world!");
}

// Yangi manzil


string destinationPath = @"C:\new_folder";

// Faylni yangi manzilga ko'chirish


File.Move(Path.Combine(sourcePath, fileName), Path.Combine(destinationPath, fileName));

Console.WriteLine("Fayl muvaffaqiyatli ko'chirildi.");


}
}
39.
Download 22.09 Kb.

Do'stlaringiz bilan baham:
1   2   3




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