#how to list the folders/files under the current directory ?

1 messages · Page 1 of 1 (latest)

steel galleon
#

i'm using 0.16 btw

steel galleon
#

i'm here but not sure how to continue:

const std = @import("std");
const print = std.debug.print;
pub fn main(init: std.process.Init) !void {
    const allocator = init.gpa;
    const io = init.io;
    var dir1 = try std.Io.Dir.cwd().openDir(io, ".", .{ .iterate = true });
    defer dir1.close(io);
    var w1 = try dir1.walk(allocator);
    defer w1.deinit();
outer veldt
#
    while(try w1.next(io)) |entry| {
        switch(entry.kind) {
            .file, .directory => {
                std.debug.print("{s} {s}\n",.{entry.path, entry.basename});
            },
            else => {},
        }
    }
#

or maybe you want to add some different formatting for folders vs files etc