juno.io.filesystem Module



char[][] logicalDrives();

Returns an array of strings containing the names of the logical drives on the current computer.

char[] getDirectoryRoot(char[] path);

Returns the volume and/or root information for the specified path.

bool directoryExists(char[] path);

Determines whether the specified path refers to an existing directory on disk.

void createDirectory(char[] path);

Creates all the directories in the specified path.

enum DeleteOption;

Specifies whether a file or directory should be deleted permanently or placed in the Recycle Bin.

DeletePermanently

Delete the file or directory permanently. Default.

AllowUndo

Allow the delete operation to be undone.

void deleteDirectory(char[] path, DeleteOption option = cast(DeleteOption)0);

Deletes the directory from the specified path.

void moveDirectory(char[] sourceDirName, char[] destDirName);

Moves a file or a directory and its contents to a new location.

DateTime getCreationTime(char[] path);

Returns the creation date and time of a directory or file.

DateTime getLastAccessTime(char[] path);

Returns the date and time a directory or file was last accessed.

DateTime getLastWriteTime(char[] path);

Returns the date and time a directory or file was last written to.

FileAttributes getFileAttributes(char[] path);

Returns the attributes of the file on the specified path.

bool fileExists(char[] path);

Determines whether the specified file exists.

void deleteFile(char[] path, DeleteOption option = cast(DeleteOption)0);

Deletes the specified file.

void moveFile(char[] sourceFileName, char[] destFileName);

Moves the specified file to a new location.

void copyFile(char[] sourceFileName, char[] destFileName, bool overwrite = false);

Copies an existing file to a new file, with the option to overwrite a file of the same name.

void replaceFile(char[] sourceFileName, char[] destFileName, char[] backupFileName, bool ignoreMergeErrors = false);

Replaces the contents of the specified file with the contents of another, deleting the original, and creating a backup of the replaced file and optionally ignores merge errors.

void encryptFile(char[] path);

Encrypts a file so that only the user account used to encrypt the file can decrypt it.

void decryptFile(char[] path);

Decrypts a file that was encrypted by the current user account using the encryptFile method.

ulong getAvailableFreeSpace(char[] driveName);

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);

ulong getTotalSize(char[] driveName);



ulong getTotalFreeSpace(char[] driveName);



char[] getVolumeLabel(char[] driveName);



void setVolumeLabel(char[] driveName, char[] volumeLabel);



enum NotifyFilters;



enum WatcherChange;



class FileSystemEventArgs: juno.base.events.EventArgs;



alias FileSystemEventHandler;



class RenamedEventArgs: juno.io.filesystem.FileSystemEventArgs;



alias RenamedEventHandler;



class ErrorEventArgs: juno.base.events.EventArgs;



alias ErrorEventHandler;



class Watcher;

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() {
   // Create a Watcher object and set its properties.
   scope watcher = new Watcher;
   watcher.path = r"C:\";

   // Add event handlers.
   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);
   };

   // Start listening.
   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);



interface Iterator(T);



int opApply(int delegate(ref T) action);



Iterator enumDirectories(char[] path, char[] searchPattern = "*");

Returns an iterable collection of directory names in the specified path.

Iterator enumFiles(char[] path, char[] searchPattern = "*");

Returns an iterable collection of file names in the specified path.

Iterator enumFileSystemEntries(char[] path, char[] searchPattern = "*");

Returns an iterable collection of file-system entries in the specified path.