authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-11-18 21:19:19 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-11-18 21:19:19 -08:00
loge7ede19e6f7cfb97574bf69b442cefa48181be12
tree3ab13064c92b75c1b4cd253be380c0d81dbc5036
parentc8d6aa1b697e6f704ac1a12fc6859055231f3449

add dirSize and fileSize


1 files changed, 21 insertions(+), 0 deletions(-)

src/lib.zig+21
...@@ -124,3 +124,24 @@ pub fn fileList(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]string {...@@ -124,3 +124,24 @@ pub fn fileList(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]string {
124 }124 }
125 return list.toOwnedSlice();125 return list.toOwnedSlice();
126}126}
127
128pub fn dirSize(alloc: *std.mem.Allocator, dir: std.fs.Dir) !usize {
129 var res: usize = 0;
130
131 var walk = try dir.walk(alloc);
132 defer walk.deinit();
133 while (try walk.next()) |entry| {
134 if (entry.kind != .File) {
135 continue;
136 }
137 res += try fileSize(dir, entry.path);
138 }
139 return res;
140}
141
142pub fn fileSize(dir: std.fs.Dir, sub_path: string) !usize {
143 const f = try dir.openFile(sub_path, .{});
144 defer f.close();
145 const s = try f.stat();
146 return s.size;
147}