pykot/fs

Search:
Group by:

Working in the file system, e.g. create an empty file.

Procs

proc check_required_programs(programs: seq[string]; halt: bool = false) {.
    ...raises: [], tags: [ReadEnvEffect, ReadDirEffect], forbids: [].}

Check if the given programs are available in the PATH.

If not found, return an empty string.

proc touch(fname: string): bool {....raises: [IOError],
                                  tags: [ReadDirEffect, WriteIOEffect],
                                  forbids: [].}

Create an empty file if the file doesn't exist.

Return true, if the file exists. Return false, if the empty file was not created. If the file exists, its date attribute won't be updated, thus it's simpler than the Unix touch command.

proc which(fname: string): string {....raises: [],
                                    tags: [ReadEnvEffect, ReadDirEffect],
                                    forbids: [].}

Find a given file in the PATH and return its full path.

If not found, return an empty string.

Templates

template withFile(f: untyped; filename: string; mode: FileMode; body: untyped)

Open a file similarly to Python's with block.

Reading a file line by line:

withFile(f, "input.txt", fmRead):
  for line if f.lines:
    echo line

Writing to a file:

withFile(f, "out.txt", fmWrite):
  f.writeLine("line 1")
  f.writeLine("line 2")