mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 09:24:36 +00:00
* stdlib organization & documentation improvements * fix CI * Update doc/lib.md Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> * fix ci, remove jshttpcore, export in jsfetch instead * fix alphabetical order violations * add cmdline, db_odbc Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
44 lines
1.3 KiB
Nim
44 lines
1.3 KiB
Nim
## This module implements file handling.
|
|
|
|
from paths import Path, ReadDirEffect, WriteDirEffect
|
|
|
|
from std/private/osfiles import fileExists, removeFile,
|
|
moveFile
|
|
|
|
|
|
proc fileExists*(filename: Path): bool {.inline, tags: [ReadDirEffect].} =
|
|
## Returns true if `filename` exists and is a regular file or symlink.
|
|
##
|
|
## Directories, device files, named pipes and sockets return false.
|
|
result = fileExists(filename.string)
|
|
|
|
proc removeFile*(file: Path) {.inline, tags: [WriteDirEffect].} =
|
|
## Removes the `file`.
|
|
##
|
|
## If this fails, `OSError` is raised. This does not fail
|
|
## if the file never existed in the first place.
|
|
##
|
|
## On Windows, ignores the read-only attribute.
|
|
##
|
|
## See also:
|
|
## * `removeDir proc <dirs.html#removeDir>`_
|
|
## * `moveFile proc`_
|
|
removeFile(file.string)
|
|
|
|
proc moveFile*(source, dest: Path) {.inline,
|
|
tags: [ReadDirEffect, ReadIOEffect, WriteIOEffect].} =
|
|
## Moves a file from `source` to `dest`.
|
|
##
|
|
## Symlinks are not followed: if `source` is a symlink, it is itself moved,
|
|
## not its target.
|
|
##
|
|
## If this fails, `OSError` is raised.
|
|
## If `dest` already exists, it will be overwritten.
|
|
##
|
|
## Can be used to `rename files`:idx:.
|
|
##
|
|
## See also:
|
|
## * `moveDir proc <dirs.html#moveDir>`_
|
|
## * `removeFile proc`_
|
|
moveFile(source.string, dest.string)
|