dirs
nimony/lib/std/dirs.nim
This module implements operations for creating, removing, and iterating over directories.
See also:
- paths module for path handling
- syncio module for file I/O
proc tryCreateFinalDir(dir: Path): ErrorCodeTries to create the final directory in a path. In other words, it tries to create a single new directory, not a nested one. It returns the OS's error code making it easy to distinguish between "could not create" and "already exists".
proc createDir(dir: Path)Creates a new directory
dir. If the directory already exists, no error is raised. This can be used to create a nested directory structure directly.proc tryRemoveFinalDir(dir: Path): ErrorCodeTries to remove the final directory in a path. In other words, it tries to remove a single directory, not a nested one. It returns the OS's error code making it easy to distinguish between "could not remove" and "does not exist".
proc removeDir(dir: Path)Removes the directory
dir. If the directory does not exist, no error is raised.proc tryRemoveFile(file: Path): ErrorCodeproc removeFile(file: Path)Removes the file
file. If the file does not exist, no error is raised.type DirEntry = object kind: PathComponent path: Path
type DirWalker = object pimpl: ptr DIR dir: Path status: ErrorCode
proc tryOpenDir(dir: sink Path): DirWalkerTries to open the directory
dirfor iteration over its entries.proc tryNextDir(w: var DirWalker; e: var DirEntry): boolproc tryCloseDir(w: var DirWalker): ErrorCodeiterator walkDir(dir: Path; relative: bool; checkDir: bool): tuple[kind: PathComponent, path: Path]Walks over all entries in the directory
dir.Yields tuples of
(kind, path)wherekindis one of:pcFile- regular filepcDir- directorypcLinkToFile- symbolic link to a filepcLinkToDir- symbolic link to a directory
If
relativeis true, yields relative paths (just the filename/dirname), otherwise yields full paths.If
checkDiris true, raises an error ifdirdoesn't exist or isn't a directory.Special directories "." and ".." are skipped.
proc getCurrentDir(): PathReturns the current working directory as a
Path.Raises an error if unable to retrieve the current directory.
See also:
setCurrentDir proc_
proc setCurrentDir(dir: Path)Sets the current working directory to
dir.Raises errors if the directory doesn't exist or lacks permissions.
See also:
getCurrentDir proc_