Coverage for video_grid_merge/delete_files.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-10 18:59 +0900
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-10 18:59 +0900
1import os
2from typing import List
4temporarily_data_list = ["_TV", ".txt"]
7def delete_files_in_folder(tmp_data_list: List[str], input_folder: str) -> None:
8 """Deletes temporary data files in the specified folder.
10 Args:
11 tmp_data_list (List[str]): List defining temporarily stored data information
12 input_folder (str): Path of the folder to be deleted
13 """
14 files_to_delete = [
15 file_name
16 for file_name in os.listdir(input_folder)
17 if any(x in file_name for x in tmp_data_list)
18 ]
19 for file_name in files_to_delete:
20 file_path = os.path.join(input_folder, file_name)
21 if os.path.isfile(file_path):
22 os.remove(file_path)
25def delete_files_with_confirmation(tmp_data_list: List[str], path: str) -> None:
26 """Ask for confirmation before deleting a file in the specified path.
28 Args:
29 tmp_data_list (List[str]): List defining temporarily stored data information
30 path (str): Path to be deleted
31 """
32 confirmation = input(
33 f"\nFiles other than input videos were created in the following paths.\n{path}\nDo you want to delete the created files?[y/N] "
34 )
35 if confirmation.lower() == "y":
36 delete_files_in_folder(tmp_data_list, path)
39if __name__ == "__main__": # pragma: no cover
40 path = "./video_grid_merge/media/input"
41 delete_files_with_confirmation(temporarily_data_list, path)