public static void deleteInfo() { List <string> logs = YINLog.FindInRange(System.DateTime.Now.AddHours(-1), System.DateTime.Now); File.Delete(path); File.AppendAllLines(path, logs); }
static void Main(string[] args) { Console.WriteLine("Disk info: "); YINDiskInfo.ShowDiskInfo(); Console.WriteLine("File info: "); YINDiskInfo.ShowFileInfo("/Volumes/BOOTCAMP/BELSTU/2 Курс/Компьютерные сети/Лабораторные работы/1 семестр/Лабораторная работа 1/Звездно-кольцевая.net"); Console.WriteLine("Directory info: "); YINDiskInfo.ShowDirInfo("/Volumes/BOOTCAMP/BELSTU/2 Курс/Компьютерные сети/Лабораторные работы/1 семестр/Лабораторная работа 1/"); YINFileManager.FileManagerActions("/Users/elijah/БГТУ/2 Курс/ООП/Лабораторные работы/Лабораторная работа 1/C-/lab13/"); YINLog.FindByDay("12"); YINLog.FindInRange(DateTime.Now.AddMinutes(-5), DateTime.Now); YINLog.FindByKeyword("Disk"); YINLog.deleteInfo(); }
public static void ShowDirInfo(string path) { YINLog.Add(Convert.ToString(MethodBase.GetCurrentMethod())); var dirInfo = new DirectoryInfo(path); Console.WriteLine($@" ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜ Number of files: {dirInfo.GetFiles().Length} Creation date: {dirInfo.CreationTime} Number of subdirectories: {dirInfo.GetDirectories().Length} Parent directory: {dirInfo.Parent} ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜ "); }
public static void ShowFileInfo(string path) { YINLog.Add(Convert.ToString(MethodBase.GetCurrentMethod())); FileInfo fileInfo = new FileInfo(path); Console.WriteLine($@" ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜ Full path: {fileInfo.DirectoryName} File name: {fileInfo.Name} File size: {fileInfo.Length} File extension: {fileInfo.Extension} Creation date: {fileInfo.CreationTime} Last changes date: {fileInfo.LastWriteTime} ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜"); }
public static void ShowDiskInfo() { YINLog.Add(Convert.ToString(MethodBase.GetCurrentMethod())); foreach (var d in DriveInfo.GetDrives()) { Console.WriteLine($@" ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜ Volume label: {d.VolumeLabel} Drive name: {d.Name} Drive file system: {d.DriveFormat} Total space: {d.TotalSize} Free space: {d.TotalFreeSpace} ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜ "); } }
public static void FileManagerActions(string disk) { YINLog.Add(Convert.ToString(MethodBase.GetCurrentMethod())); if (Directory.Exists(disk)) { var diskInf = new DirectoryInfo(disk); Console.WriteLine($"Directories in disk {disk}"); foreach (var dir in diskInf.GetDirectories()) { Console.WriteLine(dir); } Console.WriteLine(); Console.WriteLine($"Files in disk {disk}"); foreach (var files in diskInf.GetFiles()) { Console.WriteLine(files); } Console.WriteLine(); if (!Directory.Exists(@$ "{disk}YINInspect") && !File.Exists(@$ "{disk}YINInspect/YINdirinfo.txt")) { Directory.CreateDirectory(@$ "{disk}YINInspect"); //File.Create($@"{disk}YINInspect/YINdirinfo.txt"); using (StreamWriter sw = new StreamWriter(@$ "{disk}YINInspect/YINdirinfo.txt")) { foreach (var dir in diskInf.GetDirectories()) { sw.WriteLine(dir); } foreach (var files in diskInf.GetFiles()) { sw.WriteLine(files); } sw.Close(); } File.Copy(@$ "{disk}YINInspect/YINdirinfo.txt", @$ "{disk}YINInspect/YINdirinfoCopy.txt"); File.Delete(@$ "{disk}YINInspect/YINdirinfo.txt"); //xxxfilemanager B Directory.CreateDirectory(@$ "{disk}YINfiles"); var dirInfo = new DirectoryInfo($@"{disk}txts"); var yinDirInfo = new DirectoryInfo(@$ "{disk}/YINfiles"); foreach (var txt in dirInfo.GetFiles("*.txt", SearchOption.AllDirectories)) { File.Copy(txt.FullName, @$ "{disk}YINfiles/{txt.Name}"); } //xxxfilemanager C yinDirInfo.MoveTo(@$ "{disk}YINInspect/YINfiles"); ZipFile.CreateFromDirectory(@$ "{disk}YINInspect/YINfiles", @$ "{disk}YINInspect/YINfiles.zip"); ZipFile.ExtractToDirectory(@$ "{disk}YINInspect/YINfiles.zip", @$ "{disk}YINInspect/ExtractedFiles"); } else { Directory.Delete(@$ "{disk}YINInspect", true); Directory.CreateDirectory($@"{disk}YINInspect"); using (StreamWriter sw = new StreamWriter(@$ "{disk}YINInspect/YINdirinfo.txt")) { foreach (var dir in diskInf.GetDirectories()) { sw.WriteLine(dir); } foreach (var files in diskInf.GetFiles()) { sw.WriteLine(files); } sw.Close(); } File.Copy(@$ "{disk}YINInspect/YINdirinfo.txt", @$ "{disk}YINInspect/YINdirinfoCopy.txt"); File.Delete(@$ "{disk}YINInspect/YINdirinfo.txt"); //xxxfilemanager B Directory.CreateDirectory(@$ "{disk}YINfiles"); var dirInfo = new DirectoryInfo($@"{disk}txts"); var yinDirInfo = new DirectoryInfo(@$ "{disk}/YINfiles"); foreach (var txt in dirInfo.GetFiles("*.txt", SearchOption.AllDirectories)) { File.Copy(txt.FullName, @$ "{disk}YINfiles/{txt.Name}"); } //xxxfilemanager C yinDirInfo.MoveTo(@$ "{disk}YINInspect/YINfiles"); ZipFile.CreateFromDirectory(@$ "{disk}YINInspect/YINfiles", @$ "{disk}YINInspect/YINfiles.zip"); ZipFile.ExtractToDirectory(@$ "{disk}YINInspect/YINfiles.zip", @$ "{disk}YINInspect/ExtractedFiles"); } } }