Coverage for hiperta_stream/utils/file_handling_utils.py: 0%

9 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-10-21 15:21 +0000

1import shutil 

2from pathlib import Path 

3 

4 

5def copy_file_into_dir(file_path, output_dir, exist_ok=True): 

6 """Copy the file at `file_path` into `output_dir`, conserving its name. 

7 

8 Parameters 

9 ---------- 

10 file_path : pathlib.Path or str 

11 Path to the file to copy. 

12 output_dir : pathlib.Path or str 

13 Path to the output directory. 

14 exists_ok : bool 

15 If true, won't throw an error if the output directory already exists. 

16 

17 Returns 

18 ------- 

19 pathlib.Path 

20 The path to the copied file. 

21 """ 

22 file_path = Path(file_path) 

23 output_dir = Path(output_dir) 

24 output_dir.mkdir(exist_ok=exist_ok) 

25 copy_path = output_dir.joinpath(file_path.name) 

26 shutil.copy(file_path, copy_path) 

27 return copy_path