From 3ff5bdca83bb317a29d0bffb4c0cdb95fcaac814 Mon Sep 17 00:00:00 2001 From: Zikirillo2002 <128654271+Zikirillo2002@users.noreply.github.com> Date: Wed, 7 Jun 2023 01:23:08 +0500 Subject: [PATCH 1/2] Added 2.Task1 --- HomeworksDircAndFile/Program.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/HomeworksDircAndFile/Program.cs b/HomeworksDircAndFile/Program.cs index 6fb8f0f..ada9293 100644 --- a/HomeworksDircAndFile/Program.cs +++ b/HomeworksDircAndFile/Program.cs @@ -4,7 +4,27 @@ internal class Program { static void Main(string[] args) { - Console.WriteLine("Hello, World!"); + Console.WriteLine(GetDirectoryContent("D:\\github darslar\\Lesson006\\.gitignore\\")); + } + + public static string GetDirectoryContent(string path) + { + if (Directory.GetFiles(path).Length == 0 && Directory.GetDirectories(path).Length == 0) + { + return "Papka bo'sh"; + } + else if (Directory.GetFiles(path).Length == 0) + { + return "Papkalr bor"; + } + else if (Directory.GetDirectories(path).Length == 0) + { + return "Fayllar bor"; + } + else + { + return "Papkalar va fayllar bor"; + } } } } \ No newline at end of file From d4e20a0f9a4513edd4a739b1737c7dc461a3b84a Mon Sep 17 00:00:00 2001 From: Zikirillo2002 <128654271+Zikirillo2002@users.noreply.github.com> Date: Thu, 8 Jun 2023 13:54:39 +0500 Subject: [PATCH 2/2] Changed code --- HomeworksDircAndFile/Program.cs | 35 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/HomeworksDircAndFile/Program.cs b/HomeworksDircAndFile/Program.cs index ada9293..ee92091 100644 --- a/HomeworksDircAndFile/Program.cs +++ b/HomeworksDircAndFile/Program.cs @@ -4,26 +4,37 @@ internal class Program { static void Main(string[] args) { - Console.WriteLine(GetDirectoryContent("D:\\github darslar\\Lesson006\\.gitignore\\")); + Console.Write("Enter the path : "); + string path = Console.ReadLine(); + + Console.WriteLine(GetDirectoryContent(path)); } public static string GetDirectoryContent(string path) { - if (Directory.GetFiles(path).Length == 0 && Directory.GetDirectories(path).Length == 0) - { - return "Papka bo'sh"; - } - else if (Directory.GetFiles(path).Length == 0) + if(Directory.Exists(path)) { - return "Papkalr bor"; - } - else if (Directory.GetDirectories(path).Length == 0) - { - return "Fayllar bor"; + if (Directory.GetFiles(path).Length == 0 && Directory.GetDirectories(path).Length == 0) + { + return "Papka bo'sh"; + } + else if (Directory.GetFiles(path).Length == 0) + { + return "Papkalr bor"; + } + else if (Directory.GetDirectories(path).Length == 0) + { + return "Fayllar bor"; + } + else + { + return "Papkalar va fayllar bor"; + } } + else { - return "Papkalar va fayllar bor"; + return "Path ni xato kiritdingiz "; } } }