有没有办法访问std.fs.Dir结构体的完整路径?我已经查看了源代码中的所有方法,但找不到任何获取目录上路径相关信息的内容。
一种选择是realpath
std.fs.Dir.realpathAlloc (self: Dir, 分配器: 分配器, 路径名: []const u8) ![]u8
const std = @import("std");
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const alloc = arena.allocator();
std.log.info("cwd: {s}", .{
try std.fs.cwd().realpathAlloc(alloc, "."),
});
}
Run Code Online (Sandbox Code Playgroud)
realpath 内部调用std.os.getFdPath,而 Dir 上似乎没有任何函数可以立即执行此操作。