I'm kinda new to this so I'll just get to it. I'm trying to figure out how to check if ANY drive has 30 GB disk space, So far I can't seem to get it to do more than just checking the C: drive.
Probably has to do with the fact that CopyAvailableCheck() only checks the first value it gets, which is from the C: drive, but I have no clue how to fix that.
Any help would be much appreciated. Here is my code:
public class DriveCheck
{
private void CopyAvailableCheck()
{
if (FreeDriveSpace() == 1)
{
// do something
}
else if (FreeDriveSpace() == 0)
{
// Something Else
}
else if (FreeDriveSpace() == -1)
{
// Something else
}
}
public static int FreeDriveSpace()
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
if (d.IsReady == true)
{
// If total free space is more than 30 GB (default)
if (d.TotalFreeSpace >= 32212254720) // default: 32212254720
{
return 1; // If everything is OK it returns 1
}
else
{
return 0; // Not enough space returns 0
}
}
}
return -1; // Other error returns -1
}
}