digitalmars.D.bugs - [Issue 16487] New: Add function to obtain the available disk space
- via Digitalmars-d-bugs (40/40) Sep 11 2016 https://issues.dlang.org/show_bug.cgi?id=16487
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 puremagic.com Reporter: jbc.engelen 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; } } ``` --
Sep 11 2016