Skip to content
DirGetContents

DirGetContents

Description

Read directory contents into a vector. Current contents of the vector will be cleared out.

Parameters

Name Direction Description
path in Path of directory get content of.
alloc in Allocator used to back the returned vector and entry names.

Success

DirContents vector filled with directory contents data.

Failure

Returns empty vector on read error.

Usage example (Cross-references)

Usage examples (Cross-references)
    #ifdef _WIN32
    // Windows-specific implementation using FindFirstFile/FindNextFile
    DirContents DirGetContents(const char *path, Allocator *alloc) {
        if (!path || !alloc) {
            LOG_FATAL("Invalid argument");
    #else
    // APPLE or Unix based system implementation using opendir/readdir
    DirContents DirGetContents(const char *path, Allocator *alloc) {
        if (!path || !alloc) {
            LOG_FATAL("invalid arguments.");
            Str *dir_name = &dir_paths.data[i];
    
            DirContents dir_contents = DirGetContents(dir_name->data, &alloc.base);
            VecForeach(&dir_contents, dir_entry) {
                if (dir_entry.type == SYS_DIR_ENTRY_TYPE_DIRECTORY) {
Last updated on