(zig) filesystem tests

This commit is contained in:
scbj
2025-07-18 16:54:09 +02:00
parent 753163d28e
commit f5a20d500e
+15 -2
View File
@@ -2,12 +2,25 @@
//! this project serves to learn zig and test the behaviour of specific features
const std = @import("std");
const fs = std.fs;
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
for (1..10) |n| {
try stdout.print("{d} hello world\n", .{n});
var cwd = try fs.cwd().openDir(".", fs.Dir.OpenOptions{.iterate=true});
defer cwd.close();
var temp = cwd.iterate();
while (try temp.next()) |item|
{
const properties = try cwd.statFile(item.name);
const item_type = switch (properties.kind)
{
fs.Dir.Entry.Kind.directory => "directory",
fs.Dir.Entry.Kind.file => "file",
else => "other",
};
try stdout.print("{s} : {s}\n", .{item_type, item.name});
}
}