Skip to content

Instantly share code, notes, and snippets.

@drguildo
Last active September 19, 2022 18:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drguildo/4f673b179eb749da4507337fdaf05afc to your computer and use it in GitHub Desktop.
Save drguildo/4f673b179eb749da4507337fdaf05afc to your computer and use it in GitHub Desktop.
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