Skip to content

implement ".." (parent directory) for std.fs.Dir.openDir on Windows #3501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andrewrk opened this issue Oct 22, 2019 · 3 comments
Closed

implement ".." (parent directory) for std.fs.Dir.openDir on Windows #3501

andrewrk opened this issue Oct 22, 2019 · 3 comments
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. os-windows standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@andrewrk
Copy link
Member

zig/lib/std/fs.zig

Lines 768 to 772 in e839250

if (sub_path_w[0] == '.' and sub_path_w[1] == '.' and sub_path_w[2] == 0) {
// If you're looking to contribute to zig and fix this, see here for an example of how to
// implement this: https://git.midipix.org/ntapi/tree/src/fs/ntapi_tt_open_physical_parent_directory.c
@panic("TODO opening '..' with a relative directory handle is not yet implemented on Windows");
}

example zig code:

const std = @import("std");

pub fn main() anyerror!void {
    var it = try std.fs.walkPath(std.heap.direct_allocator, "..");
    while (try it.next()) |entry| {
        std.debug.warn("{}\n", entry.path);
    }
}
> zig.exe build-exe test.zig
> test.exe 
TODO opening '..' with a relative directory handle is not yet implemented on Windows
@andrewrk andrewrk added contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library. os-windows labels Oct 22, 2019
@andrewrk andrewrk added this to the 0.7.0 milestone Oct 22, 2019
@Leguu
Copy link

Leguu commented Dec 2, 2019

Is it possible to evaluate just . as an absolute file path and then remove the final bit in order to get the directory of ..?

E.g; . is C:\Users\Legu\, and therefore stripping the last bit gives you C:\Users

I'm new to contributing, so I hope this makes sense.

@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@Andoryuuta
Copy link
Contributor

Andoryuuta commented Sep 14, 2021

This appears to have been implemented by changes made in the last ~2 years.

I have just tested the following from the latest commit in the master branch (#5d14590), and can confirm it's working as expected:

const std = @import("std");

pub fn main() !void {
    const dir = try std.fs.cwd().openDir("..", .{.iterate = true});

    var walker = try dir.walk(std.heap.page_allocator);
    defer walker.deinit();

    while (try walker.next()) |entry| {
        std.debug.print("path: {s}\n", .{entry.path});
    }
}

@marler8997
Copy link
Contributor

Yeah I believe this was implemented with #7664

@andrewrk andrewrk modified the milestones: 0.10.0, 0.8.1, 0.9.0 Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. os-windows standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

4 participants