Skip to content
CryoCryo home

dir

import std::fs::dir; · source

ReadDir

type struct ReadDir {
    dirp: void*;
    base: String;
}

read_dir(p) opens a directory for iteration. ReadDir is a forward iterator yielding owned DirEntry values and skipping . and ..; order is filesystem-defined, and dropping it closes the handle.

import std::fs::dir;

mut entries: ReadDir = read_dir(p)?;
for (e in entries) {
    if (e.is_file()) { println(f"{e.name()}"); }
}

DirEntry

type struct DirEntry {
    entry_name: String;
    dtype:      u8;

    name(&this) -> Str;
    file_type(&this) -> FileType;
    is_dir(&this) -> boolean;
    is_file(&this) -> boolean;
}

DirEntry owns its name. On Linux the type comes from the dirent d_type field, which some filesystems report as unknown — that surfaces as FileType::Other, so call metadata on the full path when you need an authoritative answer. On Windows, where mingw's dirent has no d_type, each entry's Win32 attributes are read as it is yielded.

Trait implementations

implement trait Iterator<DirEntry> for struct ReadDir

implement trait Drop for struct ReadDir

implement trait Drop for struct DirEntry

Directory operations

function read_dir(p: Path) -> Result<ReadDir, IoError>;
function create_dir(p: Path) -> Result<(), IoError>;
function create_dir_all(p: Path) -> Result<(), IoError>;
function remove_file(p: Path) -> Result<(), IoError>;
function remove_dir(p: Path) -> Result<(), IoError>;
function remove_dir_all(p: Path) -> Result<(), IoError>;
function rename(from: Path, to: Path) -> Result<(), IoError>;
function canonicalize(p: Path) -> Result<PathBuf, IoError>;
FunctionNotes
create_dir(p)One directory, mode 0755. Fails if it exists or a parent is missing.
create_dir_all(p)mkdir -p. Succeeds if p already exists as a directory, and tolerates a concurrent creator racing on the same path.
remove_file(p)unlink(2) — files and symlinks.
remove_dir(p)rmdir(2) — must be empty.
remove_dir_all(p)rm -r. Symlinked entries are unlinked, not followed. Returns the first failure.
rename(from, to)rename(2) — atomic within a filesystem, EXDEV across one.
canonicalize(p)The absolute path with every symlink and .. resolved.