Module dir
Directories and file system entries (hosted)
Listing, creating, copying and removing directories, and querying what a path names. Backends: dir_posix.sc (Linux, macOS, BSD) and dir_win32.sc (Windows); the tree operations (create_all, walk, copy, remove_all) are shared, in dir.sc. Paths are '/'-separated (Windows accepts '/' too); see std/path.h for joining and normalizing them.
?&Dir d = Dir::open("docs");
match (d) {
case some(dir): {
struct DirEntry e = DirEntry::new();
while (dir.next(&e)) { println(e.name.as_ptr()); }
e.free();
dir.close();
}
case null: { eprintln("cannot open docs/"); }
}
struct Vec<struct String> files = Vec::new();
dir_walk("docs", &files); // every file below docs/, sorted
dir_copy_tree("public", "dist"); // cp -R public/. dist/
All int-returning operations return 1 on success and 0 on failure.
Structs
| DirEntry | |
| Dir | An open directory listing. |
| FileStat | What file_stat reports. |
Functions
| file_stat | Fills 'out' for 'path' (symbolic links are not followed). 0, with out.kind = DIR_NONE, if nothing is there. |
| path_kind | The kind of 'path' (DIR_NONE when nothing is there). |
| path_exists | 1 if something exists at 'path'. |
| dir_create | Creates one directory (its parent must exist). 1 also when it already exists as a directory. |
| dir_create_all | Creates 'path' and every missing parent (mkdir -p). |
| dir_remove | Removes an empty directory. |
| dir_remove_all | Removes 'path' and everything below it (rm -rf); links are removed, not followed. 1 also when nothing was there. |
| file_remove | Deletes a file (or a link). |
| file_copy | Copies the file 'from' to 'to' (created or truncated). |
| dir_walk | Appends the path of every file below 'root', relative to it and '/'-separated ("guide/intro.md"), to 'out', sorted. Directories are descended into (links to them are not); hidden entries are included. |
| dir_copy_tree | Copies everything inside 'from' into 'to' (cp -R from/. to/), creating 'to' and subdirectories as needed; existing files are overwritten. |
Macros
| DIR_NONE | What a path or directory entry names. |
| DIR_FILE | a regular file |
| DIR_DIR | a directory |
| DIR_LINK | a symbolic link (not followed) / Windows reparse point |
| DIR_OTHER | device, pipe, socket, ... |