Các bạn cho mình hỏi bài 1 mình chạy nó báo lỗi khi chạy tới ổ G(là ổ DVD của máy mình). Nó dừng và ko chạy tiếp, bạn nào biết giúp mình khắc phục với.
Sẵn tiện, bạn có code bài 2 share mình tham khảo với nha :funny:
Sẵn tiện, bạn có code bài 2 share mình tham khảo với nha :funny:
Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace Bai1 { class Program { static void Main(string[] args) { DriveInfo[] alldrive = DriveInfo.GetDrives(); string[] a; string[] b; int n; foreach (DriveInfo d in alldrive) { Console.WriteLine("Drive " + d.Name); a = Directory.GetDirectories(d.Name); b = Directory.GetFiles(d.Name); if ((a.Length == 0) && (b.Length == 0)) { Console.WriteLine("Drive Empty"); return; } for (int i = 0; i < a.Length; i++) { Console.WriteLine("\t<Folder> " + a[i]); } for (int i = 0; i < b.Length; i++) { Console.WriteLine("\t<File> " + b[i]); } Console.WriteLine(); } Console.WriteLine("What do you want do now: "); Console.WriteLine("\t1.Search all Director:"); Console.WriteLine("\t2.Add a Directory"); Console.WriteLine("\t3.Delete a Directory"); n = int.Parse(Console.ReadLine()); switch (n) { case 1: Menu1(); break; case 2: Menu2(); break; case 3: Menu3(); break; } } public static void Menu1() { Console.WriteLine("Enter the Path you want to search :"); string s = Console.ReadLine(); string[] a; string[] b; if (Directory.Exists(s)) { Console.WriteLine("Not found"); return; } a = Directory.GetDirectories(s); b = Directory.GetFiles(s); if ((a.Length == 0) && (b.Length == 0)) { Console.WriteLine("Drive Empty"); return; } for (int i = 0; i < a.Length; i++) { Console.WriteLine("\t<Folder> " + a[i]); } for (int i = 0; i < b.Length; i++) { Console.WriteLine("\t<File> " + b[i]); } } public static void Menu2() { Console.WriteLine("Enter the Path you want to search :"); string s = Console.ReadLine(); if (Directory.Exists(s)) { Console.WriteLine("Not found"); return; } string filename; string foldername; Console.WriteLine("Enter directory's name: "); foldername = Console.ReadLine(); if (!Directory.Exists(foldername)) { Directory.CreateDirectory(foldername); Console.WriteLine("Directory is created"); } else { Console.WriteLine("Directory already exists"); } Console.WriteLine("Enter file's name: "); filename = Console.ReadLine(); if (!File.Exists(filename)) { File.Create(filename); Console.WriteLine("File is created"); } else { Console.WriteLine("File already exists"); } } public static void Menu3() { Console.WriteLine("Enter the Path you want to search :"); string s = Console.ReadLine(); if (Directory.Exists(s)) { Console.WriteLine("Not found"); return; } string filename; string foldername; Console.WriteLine("Enter directory's name: "); foldername = Console.ReadLine(); if (!Directory.Exists(foldername)) { Directory.Delete(foldername); Console.WriteLine("directory is deleted"); } else { Console.WriteLine("Directory doesn't exists"); } Console.WriteLine("Enter file's name: "); filename = Console.ReadLine(); if (!File.Exists(filename)) { File.Delete(filename); Console.WriteLine("File is deleted"); } else { Console.WriteLine("File doesn't exists"); } } } }
Comment