diff --git a/HomeworksDircAndFile/Program.cs b/HomeworksDircAndFile/Program.cs index 6fb8f0f..d13bfc0 100644 --- a/HomeworksDircAndFile/Program.cs +++ b/HomeworksDircAndFile/Program.cs @@ -4,7 +4,40 @@ internal class Program { static void Main(string[] args) { - Console.WriteLine("Hello, World!"); + Console.Write("Fayl manzilini kiriting" + + "(Misol : D:\\papka nomi..\\Fayl nomi.docx) : "); + + string path = Console.ReadLine(); + + Console.Write(" Nusxani ko'chirmoqchi bo'lgan" + + " fayl manzilini kiriting" + + "(Misol : D:\\papka nomi..\\) : "); + + string newPath = Console.ReadLine(); + + CopyToFiels(path, newPath); + } + + static void CopyToFiels(string path, string newPath) + { + var fileinfo = new FileInfo(path); + + if(!File.Exists(newPath)) + { + File.Create(newPath); + } + + if(fileinfo.Exists) + { + fileinfo.CopyTo( newPath,true); + + Console.WriteLine($" {path} fayldan {newPath} " + + $"faylga nusxa ko'chirildi."); + } + else + { + Console.WriteLine($"Bunday fayl {path} mavjud emas"); + } } } } \ No newline at end of file