Last active
September 19, 2022 18:19
-
-
Save drguildo/4f673b179eb749da4507337fdaf05afc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const fs = std.fs; | |
const warn = std.debug.warn; | |
pub fn main() !void { | |
const cwd = try fs.cwd().openDir(".", fs.Dir.OpenDirOptions{ | |
.iterate = true, | |
}); | |
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); | |
defer arena.deinit(); | |
const allocator = &arena.allocator; | |
try processDirectory(cwd); | |
} | |
pub fn processDirectory(dir: fs.Dir) !void { | |
var it = dir.iterate(); | |
while (try it.next()) |item| { | |
switch (item.kind) { | |
std.fs.Dir.Entry.Kind.File => processFile(item.name), | |
std.fs.Dir.Entry.Kind.Directory => { | |
const newDir = try dir.openDir(item.name, std.fs.Dir.OpenDirOptions{}); | |
try processDirectory(newDir); | |
}, | |
else => warn("{}: {}\n", .{ item.kind, item.name }), | |
} | |
} | |
} | |
pub fn processFile(fileName: []const u8) void { | |
warn("file: {}\n", .{fileName}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment