feat(macos): add a utility function to count the number of entries in a direcrory

This commit is contained in:
utox39
2025-03-25 11:08:56 +01:00
parent 13d333dd55
commit a993c9e8a2

View File

@@ -21,3 +21,17 @@ pub fn cfStringToZigString(allocator: std.mem.Allocator, cf_string: c_iokit.CFSt
return allocator.realloc(buffer, actual_len); return allocator.realloc(buffer, actual_len);
} }
pub fn countEntries(dir_path: []const u8) !usize {
var dir = try std.fs.openDirAbsolute(dir_path, .{ .iterate = true });
defer dir.close();
var count: usize = 0;
var iter = dir.iterate();
while (try iter.next()) |_| {
count += 1;
}
return count;
}