Path type

Represents file system path such as a file, a block device, etc

Direct children types

BlockDevice
Represents a block device in a file system (S_IFBLK)
CharDevice
Represents a character device in a file system (S_IFCHR)
Dir
Represents a directory in a file system (S_IFDIR)
Direct subtypes: 1
FifoFile
Represents a fifo file in a file system (S_IFIFO)
File
Represents a file in a file system (S_IFREG)
Direct subtypes: 2
SocketFile
Represents a socket file in a file system (S_IFSOCK)
Symlink
Represents a link in a file system (S_IFLNK)

Constructors

Path(s:Str, subtype:Any=false) Source: stdlib.ngs:5234
Path constructor

Parameters

spath
subtypeReturn Path sub-type, depending on lstat() call

Returns

Path or sub-type of Path

Example

Path(".")  # <Path path=.>
Path(".", true)  # <Dir path=.>
``find tmp/v8``.map(Path(X, true)).map(Type).name.Stats()  # <Stats: {Dir=287, File=9220}>

Methods

/(a:Path, b:Path) Source: stdlib.ngs:5327
Concatenate two Path-s using /(a:Str, b:Str)

Returns

Path

Example

Path("tmp") / Path("v8")  # <Path path=tmp/v8>
/(a:Path, b:Str) Source: stdlib.ngs:5332
Concatenate two Path-s using /(a:Str, b:Str)

Returns

Path

Example

Path("tmp") / "v8"  # <Path path=tmp/v8>
>(a:Path, b:Path) Source: stdlib.ngs:5382
Same as a.path > b.path
Arg(p:Path) Source: stdlib.ngs:5393
Convert to string, appropriate for using as argument to external process.

Automatically called by NGS for syntax

$(mycommand $mypath) # mypath is Path

Example

conf_files = [Path("/usr/local/etc/some.conf"), Path("/etc/some.conf")].filter(Bool(X))
$(ls -l $*conf_files)
assert(p:Path) Source: stdlib.ngs:5487
Checks that the given path exists. Throws AssertFail otherwise.

Returns

p
basename(p:Path) Source: stdlib.ngs:5780
Get basename of the file.
Bool(p:Path) Source: stdlib.ngs:5250
Checks whether the path is accessible using access(2) and F_OK.

Returns

Bool
Bool(p:Path)experimental Source: stdlib.ngs:5263
Check whether file system object at given path is of the given type.

Example

if File("myfile.txt") ...
if Dir("my_tmp_dir") ...
chdir(p:Path) Source: stdlib.ngs:5402
Change directory. Uses CHDIR(2).

Parameters

pDirectory to cd to.

Returns

null
dir(dirname:Path, *args:Arr, **kwargs:Hash) Source: stdlib.ngs:5379
List directory contents and call cb with Path() of each found item. "." and ".." are excluded. Same as dir(dirname.path, *args)
fetch(p:Path, decode_hints:Hash={}) Source: stdlib.ngs:5875
read() and decode() the given file

Example

fetch(File("1.json"))  # Data structure, the parsed JSON
init(p:Path, s:Str) Source: stdlib.ngs:5239
Path constructor

Parameters

spath
init(p:Path, other:Path) Source: stdlib.ngs:5245
Path constructor. Duplicates other Path.

Parameters

otherPath to duplicate
init(f:File, path:Path) Source: stdlib.ngs:5759
Undocumented
init(md:MarkdownDescription, tvi:ThisVersionIndex, output_name:Str, file_path:Path)
Undocumented
JsonData(p:Path) Source: stdlib.ngs:5472
Convert Path into JSON compatible data structure - string
lstat(p:Path) Source: stdlib.ngs:5216
Issue lstat() system call. Throws StatFail if the call fails.

Returns

Stat
realpath(p:Path) Source: stdlib.ngs:7954
Undocumented

Returns

Same type as p but using absolute path
require(p:Path) Source: stdlib.ngs:8078
Undocumented
specific(p:Path) Source: stdlib.ngs:5222
EXPERIMENTAL, do not use outside of stdlib! Instantiates Path sub-type, depending on what p is
stat(p:Path) Source: stdlib.ngs:5202
Issue stat() system call. Throws StatFail if the call fails.

Returns

Stat
Str(p:Path) Source: stdlib.ngs:5298
String representation of a Path (or it's sub-type)

Returns

Str

Example

find_in_path("ls").Str()  # The string: /bin/ls