qgis_deployment_toolbelt.utils.trash_or_delete module

Util dedicated to manage removal of files and folders on disk using a configurable deletion policy: moving them to the system trash, falling back to permanent deletion when trashing fails, or skipping the trash entirely.

Author: Julien Moura (https://github.com/guts)

qgis_deployment_toolbelt.utils.trash_or_delete.get_deletion_policy() Literal['force_delete', 'trash_only', 'trash_or_delete']

Resolve the deletion policy from the QDT_DELETION_POLICY environment variable, falling back to the default when unset or invalid.

Returns:

resolved deletion policy.

Return type:

DELETION_POLICY

qgis_deployment_toolbelt.utils.trash_or_delete.move_files_to_trash_or_delete(files_to_trash: list[Path] | Path, delete_file_per_file: bool = False, policy: Literal['force_delete', 'trash_only', 'trash_or_delete'] | None = None) list[Path]

Remove files or folders from disk, according to a deletion policy.

Parameters:
  • files_to_trash (list[Path] | Path) – file/folder path or list of paths to remove.

  • delete_file_per_file (bool, optional) – only relevant for the “trash_only” and “trash_or_delete” policies. If False, it tries a single batch trash operation; if True, it works path per path. Defaults to False.

  • policy (DELETION_POLICY | None, optional) – deletion policy to apply. If None, it’s resolved from the QDT_DELETION_POLICY environment variable. Defaults to None.

Returns:

list of paths that failed to be removed (empty if all succeeded).

Return type:

list[Path]