(zig) filesystem tests
This commit is contained in:
+15
-2
@@ -2,12 +2,25 @@
|
|||||||
//! this project serves to learn zig and test the behaviour of specific features
|
//! this project serves to learn zig and test the behaviour of specific features
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const fs = std.fs;
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
const stdout = std.io.getStdOut().writer();
|
const stdout = std.io.getStdOut().writer();
|
||||||
|
|
||||||
for (1..10) |n| {
|
var cwd = try fs.cwd().openDir(".", fs.Dir.OpenOptions{.iterate=true});
|
||||||
try stdout.print("{d} hello world\n", .{n});
|
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});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user