summary refs log tree commit diff stats
path: root/lib/std/files.nim
blob: c4e0491c9957575d8fc8ba1a1e0dd40510a5804f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
## This module implements file handling.
##
## **See also:**
## * `paths module <paths.html>`_ for path manipulation

from std/paths import Path, ReadDirEffect, WriteDirEffect

from std/private/osfiles import fileExists, removeFile,
                                moveFile


proc fileExists*(filename: Path): bool {.inline, tags: [ReadDirEffect], sideEffect.} =
  ## 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)
eral.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# This file is part of ranger, the console file manager.
# License: GNU GPL version 3, see the file "AUTHORS" for details.

"""Shared objects contain singletons for shared use."""

from __future__ import (absolute_import, division, print_function)


class FileManagerAware(object):  # pylint: disable=too-few-public-methods
    """Subclass this to gain access to the global "FM" object."""
    @staticmethod
    def fm_set(fm):
        FileManagerAware.fm = fm


class SettingsAware(object):  # pylint: disable=too-few-public-methods
    """Subclass this to gain access to the global "SettingObject" object."""
    @staticmethod
    def settings_set(settings):
        SettingsAware.settings = settings