Added disk space check loop

This commit is contained in:
N00MKRAD
2021-03-09 19:20:47 +01:00
parent c7b82dca6d
commit d0dfedf02f
2 changed files with 47 additions and 0 deletions

View File

@@ -775,5 +775,30 @@ namespace Flowframes.IO
Logger.Log($"OverwriteWithText failed for '{path}': {e.Message}");
}
}
public static long GetDiskSpace(string path, bool mbytes = true)
{
try
{
string driveLetter = path.Substring(0, 2); // Make 'C:/some/random/path' => 'C:' etc
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
if (d.IsReady == true && d.Name.StartsWith(driveLetter))
{
if (mbytes)
return (long)(d.AvailableFreeSpace / 1024f / 1000f);
else
return d.AvailableFreeSpace;
}
}
}
catch (Exception e)
{
Logger.Log("Error trying to get disk space: " + e.Message, true);
}
return 0;
}
}
}