On this page
std/dirs
Source EditThis module implements directory handling.
Imports
Procs
-
proc createDir(dir: Path) {.inline, ...tags: [WriteDirEffect, ReadDirEffect], raises: [OSError, IOError], forbids: [].} -
Creates the directory
dir.The directory may contain several subdirectories that do not exist yet. The full path is created. If this fails,
OSErroris raised.It does not fail if the directory already exists because for most usages this does not indicate an error.
See also:
Source Edit -
proc existsOrCreateDir(dir: Path): bool {.inline, ...tags: [WriteDirEffect, ReadDirEffect], raises: [OSError, IOError], forbids: [].} -
Checks if a directory
direxists, and creates it otherwise.Does not create parent directories (raises
OSErrorif parent directories do not exist). Returnstrueif the directory already exists, andfalseotherwise.See also:
Source Edit -
proc moveDir(source, dest: Path) {.inline, ...tags: [ReadIOEffect, WriteIOEffect], raises: [OSError, IOError], forbids: [].} -
Moves a directory from
sourcetodest.Symlinks are not followed: if
sourcecontains symlinks, they themself are moved, not their target.If this fails,
OSErroris raised.See also:
Source Edit -
proc removeDir(dir: Path; checkDir = false) {.inline, ...tags: [WriteDirEffect, ReadDirEffect], raises: [OSError], forbids: [].} -
Removes the directory
dirincluding all subdirectories and files indir(recursively).If this fails,
OSErroris raised. This does not fail if the directory never existed in the first place, unlesscheckDir= true.See also:
Source Edit
Iterators
-
iterator walkDir(dir: Path; relative = false; checkDir = false; skipSpecial = false): tuple[kind: PathComponent, path: Path] {. ...tags: [ReadDirEffect], raises: [OSError], forbids: [].} -
Walks over the directory
dirand yields for each directory or file indir. The component type and full path for each item are returned.Walking is not recursive.
- If
relativeis true (default: false) the resulting path is shortened to be relative todir, otherwise the full path is returned. - If
checkDiris true,OSErroris raised whendirdoesn't exist. - If
skipSpecialis true, then (besides all directories) only regular files (without special "file" objects like FIFOs, device files, etc) will be yielded on Unix.
- If
-
iterator walkDirRec(dir: Path; yieldFilter = {pcFile}; followFilter = {pcDir}; relative = false; checkDir = false; skipSpecial = false): Path {. ...tags: [ReadDirEffect], raises: [OSError], forbids: [].} -
Recursively walks over the directory
dirand yields for each file or directory indir.Options
relative,checkdir,skipSpecialare explained in walkDir iterator description.Warning: Modifying the directory structure while the iterator is traversing may result in undefined behavior!Walking is recursive.
followFiltercontrols the behaviour of the iterator:yieldFilter meaning pcFileyield real files (default) pcLinkToFileyield symbolic links to files pcDiryield real directories pcLinkToDiryield symbolic links to directories followFilter meaning pcDirfollow real directories (default) pcLinkToDirfollow symbolic links to directories See also:
Source Edit
Exports
© 2006–2024 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/dirs.html