Ejemplo n.º 1
0
        //информация о каждом диске : количество, имя, свободное место, общее место, метка
        public static string GetDisksInfo()
        {
            try
            {
                DriveInfo[] drivers = DriveInfo.GetDrives();
                string      info    = $"Number of drivers: {DriveInfo.GetDrives().Length}\n";

                foreach (var driveInfo in drivers)
                {
                    try
                    {
                        info += $"\nName:\n{driveInfo.Name}\nFree space: {driveInfo.AvailableFreeSpace / 1073741824} " +
                                $"GB; \nTotal space: {driveInfo.TotalSize / 1073741824} GB; " +
                                $"\nLabel: {driveInfo.VolumeLabel}\n";

                        LNZLog.AddNote("LNZDiskInfo", driveInfo.Name);
                    }
                    catch (IOException)
                    {
                        info += $"{driveInfo} not available.\n";
                    }
                }

                return(info);
            }
            catch (DriveNotFoundException)
            {
                return("Drive not found");
            }
        }
Ejemplo n.º 2
0
 //Список родительских директорниев
 public static string GetParents(string directoryPath)
 {
     try
     {
         DirectoryInfo info = new DirectoryInfo(directoryPath);
         LNZLog.AddNote("LNZDirInfo", info.FullName);
         return(info.Parent.ToString());
     }
     catch (DirectoryNotFoundException)
     {
         return("Directory not found");
     }
 }
Ejemplo n.º 3
0
 //количество поддиректориев
 public static string GetNumberOfDirectories(string directoryPath)
 {
     try
     {
         DirectoryInfo info = new DirectoryInfo(directoryPath);
         LNZLog.AddNote("LNZDirInfo", info.FullName);
         return(info.GetDirectories().Length.ToString());
     }
     catch (DirectoryNotFoundException)
     {
         return("Directory not found");
     }
 }
Ejemplo n.º 4
0
 //свободное место на диске
 public static string GetFreeSpace(string diskName)
 {
     try
     {
         DriveInfo driveInfo = new DriveInfo(diskName);
         LNZLog.AddNote("LNZDiskInfo", driveInfo.Name);
         return((driveInfo.AvailableFreeSpace / 1073741824).ToString());
     }
     catch (DriveNotFoundException)
     {
         return("Drive not found");
     }
 }
Ejemplo n.º 5
0
 //файловая система
 public static string GetFileSystem(string diskName)
 {
     try
     {
         DriveInfo driveInfo = new DriveInfo(diskName);
         LNZLog.AddNote("LNZDiskInfo", driveInfo.Name);
         return(driveInfo.DriveFormat);
     }
     catch (DriveNotFoundException)
     {
         return("Drive not found");
     }
 }
Ejemplo n.º 6
0
        //время создания
        public static string GetCreationTime(string filename)
        {
            try
            {
                FileInfo file = new FileInfo(filename);
                LNZLog.AddNote("LNZFileInfo", file.FullName);                   //add log note
                return($"Creation time: {file.CreationTime}");
            }
            catch (FileNotFoundException)
            {
                return("File not found");

                throw;
            }
        }
Ejemplo n.º 7
0
        //имя, размер, расширение
        public static string GetMainFileInfo(string filename)
        {
            try
            {
                FileInfo file = new FileInfo(filename);
                LNZLog.AddNote("LNZFileInfo", file.FullName);
                return($"File name: {file.Name}; \nextension: {file.Extension}; \nsize: " +
                       $"{file.Length / 1024} kb.");
            }
            catch (FileNotFoundException)
            {
                return("File not found");

                throw;
            }
        }
Ejemplo n.º 8
0
        //полный путь
        public static string GetFullPath(string filename)
        {
            try
            {
                FileInfo file = new FileInfo(filename);

                LNZLog.AddNote("LNZFileInfo", file.FullName);

                return(file.FullName);
            }
            catch (FileNotFoundException)
            {
                return("File not found");

                throw;
            }
        }