-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist.d
34 lines (31 loc) · 978 Bytes
/
list.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/+dub.sdl:
name "list"
dependency "volumeinfo" path="../"
+/
import std.stdio;
import std.format;
import volumeinfo;
string formatVolume(VolumeInfo volume)
{
enum toMB = 1024*1024;
return format("%s (%s, %s, %s), %s MB free out of %s MB%s", volume.path, volume.type, volume.device, volume.label, volume.bytesAvailable/toMB, volume.bytesTotal/toMB, volume.readOnly ? ", read-only" : "");
}
void main(string[] args)
{
if (args.length > 1) {
writeln("Volumes for the passed paths: ");
foreach(arg; args[1..$]) {
try {
writefln("%s resides on %s", arg, formatVolume(VolumeInfo(arg)));
} catch(Exception e) {
stderr.writefln("Error getting volume information: %s", e.msg);
}
}
} else {
auto volumes = mountedVolumes();
writeln("Mounted volumes: ");
foreach(VolumeInfo volume; volumes) {
writeln(formatVolume(volume));
}
}
}