public static void Search() { try { Console.Write("Write path, like C:/Windows\n"); //приводим пример string path = Console.ReadLine(); //получаем строку от пользователя Console.WriteLine("path is: {0}", path); //показываем то что пользователь ввел List <string> parametrs = new List <string>(); parametrs.Add("path=" + path); XMLLogWriter.XMLWriteLog("Directory_info", parametrs); DirectoryInfo chooseddir = new DirectoryInfo(path); DirectoryInfo[] listofdirs = chooseddir.GetDirectories(); FileInfo[] listoffiles = chooseddir.GetFiles(); //Console.WriteLine(chooseddir); foreach (DirectoryInfo l1 in listofdirs) //перебираем директории 1-го уровня { Console.WriteLine("\t" + l1.FullName); //выводим директорию 1-го уровня DirectoryInfo[] l1_listofdirs = l1.GetDirectories(); //директории 2-го уровня FileInfo[] l1_listoffiles = l1.GetFiles(); //файлы 2-го уровня foreach (DirectoryInfo l2 in l1_listofdirs) //перебираем директории 2-го уровня { Console.WriteLine("\t\t" + l2.FullName); //выводим директорию 2-го уровня FileSystemInfo[] innerobjs = l2.GetFileSystemInfos(); // получаем содержимое 3-го уровня foreach (FileSystemInfo innerobj in innerobjs) { Console.WriteLine("\t\t\t" + innerobj.FullName);//выводим содержимое 3-го уровня на экран } } foreach (FileInfo f in l1_listoffiles) { Console.WriteLine("\t\t" + f.FullName);//выводим файлы 2-го уровня на экран } } foreach (FileInfo f in listoffiles) { Console.WriteLine("\t" + f.FullName);//выводим файлы 1-го уровня на экран } } catch { Console.WriteLine("Invalid data or unexisted directory");//выводим сообщение об ошибке List <string> parametrs = new List <string>(); //parametrs.Add(pathfrom); //parametrs.Add(pathto); XMLLogWriter.XMLWriteError("Directory_info", parametrs); } }
public static void Rename() { try { Console.Write("Write path to Directory, like C:/Windows\n"); string path = Console.ReadLine(); Console.Write("Write new name, like Users\n"); string name = Console.ReadLine(); List <string> parametrs = new List <string>(); parametrs.Add("path=" + path); parametrs.Add("name=" + name); XMLLogWriter.XMLWriteLog("Directory_rename", parametrs); string[] newpath_name; if (name.Contains("/")) { newpath_name = path.Split('/'); newpath_name[^ 1] = name;
public void Comand_choose() { XMLLogWriter.XMLCreateRoot(); Help(); List <string> parametrs = new List <string>(); DateTime dateStart = new DateTime(); dateStart = DateTime.Now; parametrs.Add("Time=" + dateStart.ToString()); XMLLogWriter.XMLWriteLog("Start", parametrs); bool KeepWork = true; while (KeepWork) { Console.WriteLine("write number of command"); string line = Console.ReadLine(); int.TryParse(line, out int command_number); switch (command_number) { //dir case 1: Console.WriteLine("Choosed Search"); Directory_info.Search(); //Do it! break; case 2: Console.Write("make directory\n"); Directory_make.Make(); //Do it! break; case 3: Console.Write("delete directory\n"); Directory_delete.Delete(); //Do it! break; //file case 4: Console.Write("move directory\n"); Directory_move.Move(); //Do it! break; case 5: Console.Write("rename directory\n"); Directory_rename.Rename(); //Do it! break; case 6: Console.Write("search file\n"); File_info.Info(); //Do it! break; //fffffff case 7: Console.Write("make file"); File_make.Make(); //Do it! break; case 8: Console.Write("delete file\n"); File_delete.Delete(); //Do it! break; case 9: Console.Write("move file\n"); File_move.Move(); //Do it! break; case 10: Console.Write("rename file\n"); File_rename.Rename(); //Do it! break; //help & exit case 11: //Console.Write("show help\n"); Help(); //Do it! break; case 12: Console.Write("exit\n"); DateTime dateEnd = new DateTime(); dateEnd = DateTime.Now; parametrs.Add("Time=" + dateEnd.ToString()); XMLLogWriter.XMLWriteLog("End", parametrs); KeepWork = false; //Do it! break; default: Console.Write("uncorrect value!\n"); break; } } }