[Issue 16487] New: Add function to obtain the available disk space
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Sep 11 14:20:54 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16487
Issue ID: 16487
Summary: Add function to obtain the available disk space
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: jbc.engelen at gmail.com
Would be nice to have a function that returns the available disk space on a
given path (file, directory, server share).
Something like this:
```
// Returns ulong.max when the available disk space could not be determined.
ulong getAvailableDiskSpace(string path)
{
import std.string: toStringz;
version (WINDOWS)
{
import core.sys.windows.winbase;
ULARGE_INTEGER freeBytesAvailable;
auto pathCstr = (driveName(path) ~ dirSeparator).toStringz();
bool success = GetDiskFreeSpaceExW(path, &freeBytesAvailable, null,
null);
return success ? free_bytes.QuadPart : ulong.max;
}
else
{
import core.sys.posix.sys.statvfs;
statvfs_t stats;
int err = statvfs(path.toStringz(), &stats);
return !err ? stats.f_bavail * stats.f_frsize : ulong.max;
}
}
```
--
More information about the Digitalmars-d-bugs
mailing list