Constructor to initialize state common for VFSDir implementations.
Compose path for a _child directory. Used e.g. to allow StackDir to set children's paths.
Return a copy of this VFSDir without a parent. Used for mounting.
Create the directory if it does not exist (otherwise do nothing).
Implementation of create(). Caller contract guarantees that the directory is writable.
Get a subdirectory with specified _path in the directory.
Get a range of subdirectories.
Get file with specified _path in the directory.
Get a range of files in the directory.
Access for derived classes to call copyWithoutParent() of other instances.
Remove the directory if it exists (otherwise do nothing).
Does the directory exist?
Get the name of this directory.
Get full path of this directory in the VFS.
Is it possible to write to the directory?
Construct a range from a set of directories.
Construct a range from a set of _files.
1 //Construct the directory (ordinary physical file system directory in this case): 2 VFSDir dir = new FSDir("main", "./user_data/main", Yes.writable); 3 4 //Print information about the directory: 5 writeln("name: ", dir.name, 6 ", full path: ", dir.path, 7 ", writable: ", dir.writable, 8 ", exists: ", dir.exists); 9 10 //Access a file. If it does not exist, it will be created when writing: 11 auto file = dir.file("logs/memory.log"); 12 13 //Access a subdirectory: 14 auto shaders = dir.dir("shaders"); 15 16 //Create a subdirectory. If the directory exists, nothing happens (no error): 17 auto shaders = dir.dir("does_not_exist").create(); 18 19 20 //dirs() and files() methods can be used to get ranges of files and subdirectories: 21 22 //Print paths of all immediate subdirectories and their files: 23 foreach(subdir; dir.dirs()) 24 { 25 writeln(dir.path, ":"); 26 foreach(file; subdir.files()) 27 { 28 writeln(" ", file.path); 29 } 30 } 31 32 //Print paths of all subdirectories and their subdirectories, etc. recursively: 33 foreach(subdir; dir.dirs(Yes.deep)) 34 { 35 writeln(dir.path); 36 } 37 38 //Glob patterns can be used to filter the results: 39 40 //Print paths of all immediate subdirectories with paths containg "doc": 41 foreach(subdir; dir.dirs(No.deep, "*doc*")) 42 { 43 writeln(dir.path); 44 } 45 46 //Print paths of all files in the directory and in subdirectories with paths ending with ".txt": 47 foreach(file; dir.files(Yes.deep, "*.txt")) 48 { 49 writeln(file.path); 50 }
A directory in the VFS.
Provides basic directory information and access to files and subdirectories within the directory.
Directory names in the VFS can contain any characters except /, which is used as directory separator, and the :: sequence, which is used for explicit package lookup (see StackDir).