Last active
May 16, 2020 15:14
-
-
Save drguildo/34a30f6c371caa19709a42a5e2bcfb2a 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 { | |
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