Add constraint to match only path/to/keyword1/keyword2/files containing a composite keyword keyword1/keyword2.
This commit is contained in:
@ -285,6 +285,11 @@ def copy_directory_with_contraints(input_dir_path, output_dir_path,
|
||||
select_file_keywords = select_file_keywords or []
|
||||
allowed_file_extensions = allowed_file_extensions or []
|
||||
|
||||
# Normalize paths and keywords to be consistently specified with os specific separator
|
||||
input_dir_path = os.path.normpath(input_dir_path)
|
||||
output_dir_path = os.path.normpath(output_dir_path)
|
||||
select_dir_keywords = [keyword.replace('/',os.sep) for keyword in select_dir_keywords]
|
||||
|
||||
date = created_at('%Y_%m').replace(":", "-")
|
||||
log_dir='logs/'
|
||||
setup_logging(log_dir, f"copy_directory_with_contraints_{date}.log")
|
||||
@ -312,6 +317,10 @@ def copy_directory_with_contraints(input_dir_path, output_dir_path,
|
||||
for subpath in paths:
|
||||
|
||||
for dirpath, _, filenames in os.walk(subpath,topdown=False):
|
||||
|
||||
# Ensure composite keywords e.g., <keyword>/<keyword> are contained in the path
|
||||
if not any([keyword in dirpath for keyword in select_dir_keywords]):
|
||||
continue
|
||||
|
||||
# Reduce filenames to those that are admissible
|
||||
admissible_filenames = [
|
||||
|
Reference in New Issue
Block a user