public static void Move() { try { Console.Write("Write path to file, like C:/Windows/file1, where file1 is aim\n"); string pathfrom = Console.ReadLine(); Console.Write("Write path to new location, like C:/Users/file1\n"); string pathto = Console.ReadLine(); Console.WriteLine("path from: {0}", pathfrom); Console.WriteLine("path to: {0}", pathto); List <string> parametrs = new List <string>(); parametrs.Add("pathfrom=" + pathfrom); parametrs.Add("pathto=" + pathto); XMLLogWriter.XMLWriteLog("File_move", parametrs); File.Move(pathfrom, pathto); Console.WriteLine("File moved successful"); } catch { Console.WriteLine("Invalid data or unexisted file");//выводим сообщение об ошибке List <string> parametrs = new List <string>(); //parametrs.Add(pathfrom); //parametrs.Add(pathto); XMLLogWriter.XMLWriteError("File_move", parametrs); } }
public static void Delete() { try { Console.Write("Write path to Directory, like C:/Windows\n"); string path = Console.ReadLine(); if (Directory.Exists(path)) { List <string> parametrs = new List <string>(); parametrs.Add("path=" + path); XMLLogWriter.XMLWriteLog("Directory_delete", parametrs); Directory.Delete(path); Console.Write("Directory deleted successful\n"); } else { Console.WriteLine("Directory doesn't exists\n"); //ToXML.ErrorLog("Directory doesn't exists"); } } catch { Console.WriteLine("Invalid data or unexisted directory"); //выводим сообщение об ошибке List <string> parametrs = new List <string>(); //parametrs.Add(pathfrom); //parametrs.Add(pathto); XMLLogWriter.XMLWriteError("Directory_delete", parametrs); } }
public static void Delete() { try { Console.Write("Write path to file, like C:/Windows\n"); string path = Console.ReadLine(); if (File.Exists(path)) { List <string> parametrs = new List <string>(); parametrs.Add("path=" + path); XMLLogWriter.XMLWriteLog("File_delete", parametrs); File.Delete(path); Console.Write("File deleted successful\n"); } else { Console.WriteLine("File doesn't exists\n"); } } catch { Console.WriteLine("Invalid data or unexisted file"); //выводим сообщение об ошибке List <string> parametrs = new List <string>(); //parametrs.Add(pathfrom); //parametrs.Add(pathto); XMLLogWriter.XMLWriteError("File_delete", parametrs); } //C:/Users/Aleksandr/Desktop/summerWork/fatWork }
public static void Make() { try { Console.Write("Write path to Directory, like C:/Windows\n"); string path = Console.ReadLine(); if (Directory.Exists(path)) { Console.WriteLine("Directory already exists\n"); } else { List <string> parametrs = new List <string>(); parametrs.Add("path=" + path); XMLLogWriter.XMLWriteLog("Directory_make", parametrs); Directory.CreateDirectory(path); Console.Write("Directory created successful\n"); } } catch { List <string> parametrs = new List <string>(); //parametrs.Add(pathfrom); //parametrs.Add(pathto); XMLLogWriter.XMLWriteError("Directory_make", parametrs); Console.WriteLine("Invalid data or unexisted directory"); //выводим сообщение об ошибке } }
public static void Make() { try { Console.Write("Write path to file, like C:/Windows\n"); string path = Console.ReadLine(); if (File.Exists(path)) { Console.WriteLine("File already exists\n"); } else { List <string> parametrs = new List <string>(); parametrs.Add("path=" + path); XMLLogWriter.XMLWriteLog("File_make", parametrs); //File.Create(path); using (StreamWriter sw = new StreamWriter(path, false, System.Text.Encoding.Default)) { sw.WriteLine(""); } Console.Write("File created successful\n"); } } catch { Console.WriteLine("Invalid data or unexisted file"); //выводим сообщение об ошибке List <string> parametrs = new List <string>(); //parametrs.Add(pathfrom); //parametrs.Add(pathto); XMLLogWriter.XMLWriteError("File_make", parametrs); } }
public static void Info() { 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("File_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 file");//выводим сообщение об ошибке List <string> parametrs = new List <string>(); //parametrs.Add(pathfrom); //parametrs.Add(pathto); XMLLogWriter.XMLWriteError("File_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; } } }