utils.files module

class IMTreatment.utils.files.Files[source]

Bases: object

add_file(path)[source]
build_tree()[source]

Build a file tree

copy()[source]
delete_existing_files(recursive=False)[source]
get_tree_representation(max_file_list=10, hide_top=False)[source]
load_files_from_regex(rootpath, regex, load_files=True, load_dirs=True, depth='all')[source]

Load existing files from a regular expression.

remove_empty_directories()[source]
remove_files(arg)[source]

Remove some files from the files set.

Parameters:arg (integer, regex or array of integer or regex) – If integer, remove the associated path, if a regex, remove the paths that match, if an array, delete paths for each element.
IMTreatment.utils.files.remove_files_in_dirs(rootpath, dir_regex, file_regex, depth='all', remove_dir=False, remove_files=True)[source]

make a recursive search for directories satisfying “dir_regex’ from “rootpath”, and remove all the files satisfying ‘file_regex’ in it.

Parameters:
  • rootpath (string) – Path where to begin searching.
  • dir_regex (string) – Regular expression matching the directory where we want to remove stuff.
  • file_regex (string) – Regular expression matching the files we want to delete.
  • depth (integer or 'all') – Number of directory layer to go through.
  • remove_dir