# dupeGuru 4.1.0 documentation

## core.directories

exception `core.directories.``AlreadyThereError`

  The path being added is already in the directory list

exception `core.directories.``InvalidPathError`

  The path being added is invalid

class `core.directories.``Directories`(exclude_list=None)

  Holds user folder selection.

  Manages the selection that the user make through the folder selection dialog. It also manages folder states, and how recursion applies to them.

  Then, when the user starts the scan, `get_files()` is called to retrieve all files (wrapped in `core.fs`) that have to be scanned according to the chosen folders/states.

  `add_path`(path)

    Adds `path` to self, if not already there.

    Raises `AlreadyThereError` if `path` is already in self. If path is a directory containing some of the directories already present in self, `path` will be added, but all directories under it will be removed. Can also raise `InvalidPathError` if `path` does not exist.

    Parameters

      path (Path) – path to add

  `get_files`(fileclasses=None, j=<hscommon.jobprogress.job.NullJob object>)

    Returns a list of all files that are not excluded.

    Returned files also have their `is_ref` attr set if applicable.

  `get_folders`(folderclass=None, j=<hscommon.jobprogress.job.NullJob object>)

    Returns a list of all folders that are not excluded.

    Returned folders also have their `is_ref` attr set if applicable.

  `get_state`(path)

    Returns the state of `path`.

    Return type

      `DirectoryState`

  static `get_subfolders`(path)

    Returns a sorted list of paths corresponding to subfolders in `path`.

    Parameters

      path (Path) – get subfolders from there

    Return type

      list of Path

  `has_any_file`()

    Returns whether selected folders contain any file.

    Because it stops at the first file it finds, it’s much faster than get_files().

    Return type

      bool

  `load_from_file`(infile)

    Load folder selection from `infile`.

    Parameters

      infile (file) – path or file pointer to XML generated through `save_to_file()`

  `save_to_file`(outfile)

    Save folder selection as XML to `outfile`.

    Parameters

      outfile (file) – path or file pointer to XML file to save to.

  `set_state`(path, state)

    Set the state of folder at `path`.

    Parameters

      - path (Path) – path of the target folder

      - state (`DirectoryState`) – state to set folder to

class `core.directories.``DirectoryState`

  Enum describing how a folder should be considered.

  - DirectoryState.Normal: Scan all files normally

  - DirectoryState.Reference: Scan files, but make sure never to delete any of them

  - DirectoryState.Excluded: Don’t scan this folder