walkdir

    A deterministic walkdir library for MoonBit.

    walkdir
    filesystem
    fs
    Download zip
    Author
    Version
    0.1.8
    License
    MIT
    Last updated
    8 days ago
    Downloads
    65

    Dependencies

    #walkdir

    Deterministic directory walking for MoonBit.

    ///|
    test "walkdir basic example" {
    let files = @walkdir.walk_files("testdata/walk_fixture", max_depth=1)
    assert_eq(files.length(), 2)
    }

    WalkError

    pub(all) suberror WalkError {
    NotFound(String)
    NotDirectory(String)
    } derive(
    Debug
    )

    Describes errors raised before traversal starts.
    impl Show for WalkError

    WalkError::output

    fn WalkError::output(error : WalkError, logger : &Logger) -> Unit

    WalkError::to_repr

    automatically derived

    WalkError::to_string

    fn WalkError::to_string(self : WalkError) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    DirEntry

    pub(all) struct DirEntry {
    path : String
    depth : Int
    kind : EntryKind
    } derive(Eq, ToJson,
    Debug
    )

    Represents one item returned by directory traversal.

    path is the full path returned by the walker, depth is the nesting level relative to the requested root, and kind tells whether the entry is a file or directory.
    impl Show for DirEntry

    DirEntry::equal

    fn DirEntry::equal(DirEntry, DirEntry) -> Bool
    automatically derived

    DirEntry::is_dir

    fn DirEntry::is_dir(entry : DirEntry) -> Bool

    Returns true when this entry represents a directory.

    Example

    test "DirEntry::is_dir example" {
    let entry = @walkdir.DirEntry::{ path: "demo", depth: 0, kind: Dir }
    assert_true(entry.is_dir())
    }

    DirEntry::is_file

    fn DirEntry::is_file(entry : DirEntry) -> Bool

    Returns true when this entry represents a file.

    Example

    test "DirEntry::is_file example" {
    let entry = @walkdir.DirEntry::{ path: "demo.txt", depth: 1, kind: File }
    assert_true(entry.is_file())
    }

    DirEntry::not_equal

    fn DirEntry::not_equal(x : DirEntry, y : DirEntry) -> Bool

    DirEntry::output

    fn DirEntry::output(entry : DirEntry, logger : &Logger) -> Unit

    DirEntry::to_json

    fn DirEntry::to_json(DirEntry) -> Json
    automatically derived

    DirEntry::to_repr

    automatically derived

    DirEntry::to_string

    fn DirEntry::to_string(self : DirEntry) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    EntryKind

    pub(all) enum EntryKind {
    File
    Dir
    } derive(Eq, ToJson,
    Debug
    )

    Describes whether a walked entry is a file or a directory.
    impl Show for EntryKind

    EntryKind::equal

    fn EntryKind::equal(EntryKind, EntryKind) -> Bool
    automatically derived

    EntryKind::not_equal

    fn EntryKind::not_equal(x : EntryKind, y : EntryKind) -> Bool

    EntryKind::output

    fn EntryKind::output(kind : EntryKind, logger : &Logger) -> Unit

    EntryKind::to_json

    fn EntryKind::to_json(EntryKind) -> Json
    automatically derived

    EntryKind::to_repr

    automatically derived

    EntryKind::to_string

    fn EntryKind::to_string(self : EntryKind) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    walk

    fn walk(root : String, include_root? : Bool, include_dirs? : Bool, max_depth? : Int, sort? : Bool) -> Array[DirEntry] raise

    Walks a directory tree in deterministic depth-first order.

    Children are sorted lexicographically by default so repeated runs produce the same output. Set include_root=false to skip the root entry and include_dirs=false to emit only files. max_depth=0 keeps traversal at the root level.

    Parameters

    • root: The directory to traverse.
    • include_root: Whether the returned array should include the root itself.
    • include_dirs: Whether directories should be included in the returned array.
    • max_depth: The maximum depth to descend from root.
    • sort: Whether to sort each directory's children before traversal.

    Errors

    • Raises WalkError::NotFound(root) when root does not exist.
    • Raises WalkError::NotDirectory(root) when root is not a directory.

    Example

    test "walk example" {
    let entries = @walkdir.walk("testdata/walk_fixture", max_depth=1)
    assert_eq(entries.length(), 4)
    }

    walk_files

    fn walk_files(root : String, max_depth? : Int, sort? : Bool) -> Array[String] raise

    Walks a directory tree and returns only file paths.

    This is a convenience wrapper around walk(..., include_dirs=false,include_root=false) for file-oriented use cases such as indexing or filtering.

    Parameters

    • root: The directory to traverse.
    • max_depth: The maximum depth to descend from root.
    • sort: Whether to sort each directory's children before traversal.

    Errors

    Raises the same errors as walk.

    Example

    test "walk_files example" {
    let files = @walkdir.walk_files("testdata/walk_fixture")
    assert_eq(files.length(), 4)
    }

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io