//http://bbinjest.codeplex.com/
//Apache License 2.0 (Apache)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
namespace BneyBaruch.Ingest.Utils.FileSystem
{
public static class DriveUtil
{
///
/// Check drive free space.
///
/// Drive name to check free space.
/// Minimum space in bytes.
///
public static bool IsEnoughSpace(string driveName, long minimumSpace)
{
if (string.IsNullOrEmpty(driveName))
throw new ArgumentNullException("driveName");
string formattedDriveName = driveName + @":\";
DriveInfo[] drives = DriveInfo.GetDrives();
DriveInfo drive = drives.FirstOrDefault(
delegate(DriveInfo innerDrive)
{
return string.Compare(innerDrive.Name, formattedDriveName, true) == 0;
}
);
if (drive == null)
throw new DriveNotFoundException(string.Format("Drive {0} could not be found.", formattedDriveName));
if( !drive.IsReady)
throw new DriveNotFoundException(string.Format("Drive {0} is not ready.", formattedDriveName));
return drive.TotalFreeSpace > minimumSpace;
}
}
}