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); } }