VFSDir

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

Constructors

this
this(VFSDir parent, string pathInParent)

Constructor to initialize state common for VFSDir implementations.

Members

Functions

composePath
string composePath(const VFSDir child)

Compose path for a _child directory. Used e.g. to allow StackDir to set children's paths.

copyWithoutParent
VFSDir copyWithoutParent()

Return a copy of this VFSDir without a parent. Used for mounting.

create
void create()

Create the directory if it does not exist (otherwise do nothing).

create_
void create_()

Implementation of create(). Caller contract guarantees that the directory is writable.

dir
VFSDir dir(string path)

Get a subdirectory with specified _path in the directory.

dirs
VFSDirs dirs(Flag!"deep" deep = No.deep, string glob = null)

Get a range of subdirectories.

file
VFSFile file(string path)

Get file with specified _path in the directory.

files
VFSFiles files(Flag!"deep" deep = No.deep, string glob = null)

Get a range of files in the directory.

getCopyWithoutParent
VFSDir getCopyWithoutParent(VFSDir dir)

Access for derived classes to call copyWithoutParent() of other instances.

remove
void remove()

Remove the directory if it exists (otherwise do nothing).

Properties

exists
bool exists [@property getter]

Does the directory exist?

name
string name [@property getter]

Get the name of this directory.

path
string path [@property getter]

Get full path of this directory in the VFS.

writable
bool writable [@property getter]

Is it possible to write to the directory?

Static functions

dirsRange
VFSDirs dirsRange(VFSDirs.Items dirs)

Construct a range from a set of directories.

filesRange
VFSFiles filesRange(VFSFiles.Items files)

Construct a range from a set of _files.

Examples

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 }

Meta