Skip to content

Instantly share code, notes, and snippets.

@drguildo
Last active May 16, 2020 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drguildo/34a30f6c371caa19709a42a5e2bcfb2a to your computer and use it in GitHub Desktop.
Save drguildo/34a30f6c371caa19709a42a5e2bcfb2a 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 {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = &arena.allocator;
const cwd = try fs.cwd().openDir(".", fs.Dir.OpenDirOptions{
.iterate = true,
});
processDirectory(allocator, cwd);
}
pub fn processDirectory(allocator: *std.mem.Allocator, dir: fs.Dir) void {
var it = dir.iterate();
while (try it.next()) |item| {
var absolutePath = try fs.realpathAlloc(allocator, item.name);
defer allocator.free(absolutePath);
warn("{}\n", .{absolutePath});
const file = dir.openFile(item.name, fs.File.OpenFlags{
.read = true,
.write = false,
}) catch |err| {
warn("{}\n", .{err});
break;
};
warn("{}\n", .{file});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment