Function deleteFile [src]
Prototype
pub fn deleteFile(self: Dir, sub_path: []const u8) DeleteFileError!void
Parameters
self: Dir
sub_path: []const u8
Possible Errors
In WASI, this error may occur when the file descriptor does not hold the required rights to unlink a resource by path relative to it.
On Windows, file paths cannot contain these characters: '/', '*', '?', '"', '<', '>', '|'
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.
The Operating System returned an undocumented error code.
This error is in theory not possible, but it would be better to handle this error than to invoke undefined behavior.
When this error code is observed, it usually means the Zig Standard Library needs a small patch to add the error code to the error set for the respective function.
Source
pub fn deleteFile(self: Dir, sub_path: []const u8) DeleteFileError!void {
if (native_os == .windows) {
const sub_path_w = try windows.sliceToPrefixedFileW(self.fd, sub_path);
return self.deleteFileW(sub_path_w.span());
} else if (native_os == .wasi and !builtin.link_libc) {
posix.unlinkat(self.fd, sub_path, 0) catch |err| switch (err) {
error.DirNotEmpty => unreachable, // not passing AT.REMOVEDIR
else => |e| return e,
};
} else {
const sub_path_c = try posix.toPosixPath(sub_path);
return self.deleteFileZ(&sub_path_c);
}
}