Import with #import "std/file_tree_linux".
PathKind :: enum { Missing = 0; File = 1; Directory = 2; Link = 3; Other = 4; }PathInfo :: struct { kind: PathKind; owner_uid: u32; mode: s32; size: s64; modified: s64; modified_nanoseconds: u32; metadata_mask: u32; identity_valid: bool; inode: u64; changed: s64; changed_nanoseconds: u32; device_major: u32; device_minor: u32; }PathQueryResult :: struct { info: PathInfo; valid: bool; missing: bool; error: s32; }A failed query has zero info. Only ENOENT/ENOTDIR mean missing; error otherwise preserves the positive Linux errno (EINVAL for invalid text).
PathQuery :: (path: string, follow_links: bool) -> PathQueryResultFollows links by default. Invalid text contains NUL or exceeds 4095 bytes.
PathStatus :: (path: string, follow_links: bool) -> PathInfoThe path's metadata, or zero info on any failure. Use PathQuery when the distinction between a missing path and another error matters.
FileSnapshot :: (path: string) -> PathInfoA complete identity of a regular file without following its final symlink.
SameFileSnapshot :: (left: PathInfo, right: PathInfo) -> boolIsFile :: (path: string) -> boolIsDirectory :: (path: string) -> boolSetPathMode :: (path: string, mode: s32) -> boolJoinPath :: (directory: string, name: string) -> TextDIRECTORY/NAME, or NAME alone when it is absolute or DIRECTORY is empty.
PathName :: (path: string) -> stringThe last part of PATH, after its final slash.
PathParent :: (path: string) -> stringPATH without its last part: "." for a bare name, "/" for a root entry.
PathSuffix :: (path: string) -> stringThe name's extension with its dot, as Python's Path.suffix: ".png".
PathStem :: (path: string) -> stringThe name without its extension, as Python's Path.stem.
ResolvePath :: (path: string) -> TextThe absolute path with every link and dot resolved; empty when PATH does not exist.
CreateTemporaryDirectory :: (parent: string, prefix: string) -> TextAtomically creates a unique private child of an existing caller-owned parent. The parent and its ancestors must stay at stable paths during the call. PREFIX is a single name component; six random characters follow it. Returns the canonical absolute child path, or empty on failure. The caller owns the returned allocation and directory cleanup with RemoveTree. Permissions are 0700, restricted by umask.
WorkingDirectory :: () -> TextCreateDirectories :: (path: string, mode: s32) -> boolCreates PATH and every missing parent folder; true when it exists as a folder afterwards.
FreeDirectoryNames :: (names: *Vec(string))Release every independently owned name returned by ListDirectory and the vector storage, resetting the vector to empty. Do not mix borrowed strings or duplicate ownership into this vector. Empty, repeated and null calls are harmless; all borrowed views of its names expire at this call.
ListDirectory :: (path: string, names: *Vec(string)) -> boolThe names in a folder, without "." and "..", sorted by their bytes. Appends independently owned entry names in sorted order. The caller owns each nonempty string as well as the Vec; release both with FreeDirectoryNames. Failed scans append nothing.
RemoveTree :: (path: string) -> boolRemoves PATH and, for a folder, everything in it. Links are removed, never followed. True when nothing remains at PATH. All traversal scratch is freed.
CopyFile :: (source: string, target: string) -> boolCopies a file's bytes and permission bits to TARGET, replacing it.
CopyTree :: (source: string, target: string) -> boolCopies a folder and everything in it to TARGET, which is created; links inside are copied as links.
CopySymbolicLink :: (source: string, target: string) -> boolCopy the symbolic link itself, including a dangling or directory link. The native symlink operation fails when TARGET is occupied.
CopyFileNew :: (source: string, target: string) -> boolCopy to an exclusively created private file, preserving permission bits on success. An incomplete file remains private. Links are copied as links. Failure may leave a partial new file; never removes a destination. Keep source and destination ancestors stable during copying.
CopyTreeNew :: (source: string, target: string) -> boolCopy into a new directory under an existing parent, with exclusive child creation and links preserved. Reject self/descendant destinations, including aliases through symlink parents. Failure may leave a partial new tree, with no rollback deletion. Ancestors and source entries must remain stable.
ReplaceFile :: (path: string, text: string) -> boolReplaces the file at PATH with TEXT so that readers see either the old or the new whole file: a private sibling file is written, synced and renamed over it. The new file keeps the old one's permission bits.
LockPath :: (path: string, exclusive: bool, wait: bool) -> s32Opens (creating) the lock file at PATH and takes its flock: exclusive or shared, waiting or not. Returns the descriptor to UnlockPath, or -1 when the file cannot be opened or, without wait, another holder has it.
UnlockPath :: (fd: s32)MatchName :: (name: string, pattern: string) -> boolWhether NAME matches a shell wildcard PATTERN: * any run, ? one byte, [abc], [a-z] and [!abc] one byte of a set. Nothing else is special.