I need code that can both compile under Visual Studio & Mono, & run on Linux or Windows.
I need to return the free space available given only the path to the directory.
On windows I'd do something along the lines of -
var file = new FileInfo(path);
var drive = new DriveInfo(file.Directory.Root.FullName);
return drive.AvailableFreeSpace;
However on Linux this seems to throw an Argument Exception. file.Directory.Root.FullName returns '/'. DriveInfo throws an Argument Exception of 'The drive name does not exist'
Any ideas?
Thanks
You can simply use the linux df command. This will return you a summary of all available disks on your computer.
The function GetDiskSpace returns a table of the following form:
Filesystem | 1K-blocks | Used | Available | Use% | Mounted on
/dev/sda4 | 497240864 | 31182380 | 466058484 | 7% | /