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