query
On this page

readFileType

lib.readFileType

Primop
Docs pulled from | This Revision | 18 minutes ago


Nixpkgs manual

The type of a path. The path needs to exist and be accessible. The result is either "directory" for a directory, "regular" for a regular file, "symlink" for a symlink, or "unknown" for anything else.

Inputs

path

The path to query

Type

pathType :: Path -> String

Examples

lib.filesystem.pathType usage example

pathType /.
=> "directory"

pathType /some/file.nix
=> "regular"
(lib.filesystem.pathType)

Nix manual

Takes 1 arguments

p

Determine the directory entry type of a filesystem node, being one of "directory", "regular", "symlink", or "unknown".

Noogle detected

Aliases

Implementation

This function is implemented in c++ and is part of the native nix runtime.

src/libexpr/primops.cc:2387

static void prim_readFileType(EvalState & state, const PosIdx pos, Value ** args, Value & v)
{
    auto path = state.realisePath(pos, *args[0], std::nullopt);
    /* Retrieve the directory entry type and stringize it. */
    v = fileTypeToString(state, path.lstat().type);
}