Function deleteDir [src]
Returns error.DirNotEmpty if the directory is not empty.
To delete a directory recursively, see deleteTree.
On Windows, sub_path should be encoded as WTF-8.
On WASI, sub_path should be encoded as valid UTF-8.
On other platforms, sub_path is an opaque sequence of bytes with no particular encoding.
Asserts that the path parameter has no null bytes.
Prototype
pub fn deleteDir(self: Dir, sub_path: []const u8) DeleteDirError!void
Parameters
self: Dir
sub_path: []const u8
Possible Errors
WASI-only; file paths must be valid UTF-8.
Windows-only; file paths provided by the user must be valid WTF-8. https://simonsapin.github.io/wtf-8/
On Windows, \\server
or \\server\share
was not found.
Source
pub fn deleteDir(self: Dir, sub_path: []const u8) DeleteDirError!void {
if (native_os == .windows) {
const sub_path_w = try windows.sliceToPrefixedFileW(self.fd, sub_path);
return self.deleteDirW(sub_path_w.span());
} else if (native_os == .wasi and !builtin.link_libc) {
posix.unlinkat(self.fd, sub_path, posix.AT.REMOVEDIR) catch |err| switch (err) {
error.IsDir => unreachable, // not possible since we pass AT.REMOVEDIR
else => |e| return e,
};
} else {
const sub_path_c = try posix.toPosixPath(sub_path);
return self.deleteDirZ(&sub_path_c);
}
}