files.nim 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from paths import Path, ReadDirEffect, WriteDirEffect
  2. from std/private/osfiles import fileExists, removeFile,
  3. moveFile
  4. proc fileExists*(filename: Path): bool {.inline, tags: [ReadDirEffect].} =
  5. ## Returns true if `filename` exists and is a regular file or symlink.
  6. ##
  7. ## Directories, device files, named pipes and sockets return false.
  8. result = fileExists(filename.string)
  9. proc removeFile*(file: Path) {.inline, tags: [WriteDirEffect].} =
  10. ## Removes the `file`.
  11. ##
  12. ## If this fails, `OSError` is raised. This does not fail
  13. ## if the file never existed in the first place.
  14. ##
  15. ## On Windows, ignores the read-only attribute.
  16. ##
  17. ## See also:
  18. ## * `removeDir proc <dirs.html#removeDir>`_
  19. ## * `moveFile proc`_
  20. removeFile(file.string)
  21. proc moveFile*(source, dest: Path) {.inline,
  22. tags: [ReadDirEffect, ReadIOEffect, WriteIOEffect].} =
  23. ## Moves a file from `source` to `dest`.
  24. ##
  25. ## Symlinks are not followed: if `source` is a symlink, it is itself moved,
  26. ## not its target.
  27. ##
  28. ## If this fails, `OSError` is raised.
  29. ## If `dest` already exists, it will be overwritten.
  30. ##
  31. ## Can be used to `rename files`:idx:.
  32. ##
  33. ## See also:
  34. ## * `moveDir proc <dirs.html#moveDir>`_
  35. ## * `removeFile proc`_
  36. moveFile(source.string, dest.string)