Example #1
0
        private void cboDrives_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboDrives.SelectedIndex < 0)
            {
                return;
            }

            StringBuilder sb = new StringBuilder();
            DriveInfo     di = cboDrives.SelectedItem as DriveInfo;

            sb.AppendLine(di.Name + ": ");
            if (di.IsNotNull())
            {
                if (di.IsReady)
                {
                    sb.AppendLine("VolumeLabel: " + di.VolumeLabel);
                    sb.AppendLine("RootDirectory: " + di.RootDirectory.FullName);
                    sb.AppendLine("DriveFormat: " + di.DriveFormat);
                    sb.AppendLine("DriveType: " + di.DriveType.ToString());
                    sb.AppendLine("AvailableFreeSpace: " + di.AvailableFreeSpace);
                    sb.AppendLine("TotalFreeSpace: " + di.TotalFreeSpace);
                    sb.AppendLine("TotalSize: " + di.TotalSize);
                }
                else
                {
                    sb.AppendLine("Drive Not Ready.");
                }
            }

            txtDetails.Text = sb.ToString();
        }
        public static double AvailableFreeSpaceGb(this DriveInfo driveInfo, int decimals = 1)
        {
            Contract.Requires(driveInfo.IsNotNull());

            var divisor = Math.Pow(1024, 3);
            var result  = driveInfo.TotalFreeSpace / divisor;

            return(Math.Round(result, 1));
        }