Examples
Converts a numeric value into a human-readable string representing the number expressed in bytes, kilobytes, megabytes or gigabytes.
string[] orders = [ "GB", "MB", "KB", " bytes" ];
const real scale = 1024;
auto max = std.math.pow(scale, orders.length - 1);
string drive = r"C:\";
auto freeSpace = getAvailableFreeSpace(drive);
string s = "0 bytes";
foreach (order; orders) {
if (freeSpace > max) {
s = std.string.format("%.2f%s", cast(real)freeSpace / max, order);
break;
}
max /= scale;
}
std.stdio.writefln("Available free space on drive %s: %s", drive, s);
Listens to file system change notifications and raises events when a directory, or file in a directory, changes.
Examples
import juno.io.filesystem, std.stdio;
void main() {
scope watcher = new Watcher;
watcher.path = r"C:\";
watcher.created += (Object, FileSystemEventArgs e) {
writefln("File %s changed", e.fullPath);
};
watcher.deleted += (Object, FileSystemEventArgs e) {
writefln("File %s deleted", e.fullPath);
};
watcher.changed += (Object, FileSystemEventArgs e) {
writefln("File %s changed", e.fullPath);
};
watcher.renamed += (Object, RenamedEventArgs e) {
writefln("File %s renamed to %s", e.oldFullPath, e.fullPath);
};
watcher.enableEvents = true;
writefln("Press 'q' to quit.");
while (std.c.stdio.getch() != 'q') {
}
}
FileSystemEventHandler created;
FileSystemEventHandler deleted;
FileSystemEventHandler changed;
RenamedEventHandler renamed;
ErrorEventHandler error;
this(string path = null, string filter = "*");
final void bufferSize(uint value);
final uint bufferSize();
final void path(char[] value);
final char[] path();
final void filter(char[] value);
final char[] filter();
final void notifyFilters(NotifyFilters value);
final NotifyFilters notifyFilters();
final void enableEvents(bool value);
protected void onCreated(FileSystemEventArgs e);
protected void onDeleted(FileSystemEventArgs e);
protected void onChanged(FileSystemEventArgs e);
protected void onRenamed(RenamedEventArgs e);
protected void onError(ErrorEventArgs e);