66from automation_file .utils .logging .loggin_instance import file_automation_logger
77
88
9- def copy_file (file_path : str , target_path : str ) -> bool :
9+ def copy_file (file_path : str , target_path : str , copy_metadata : bool = True ) -> bool :
1010 """
1111 :param file_path: which file do we want to copy (str path)
1212 :param target_path: put copy file on target path
13+ :param copy_metadata: copy file metadata or not
1314 :return: True if success else False
1415 """
1516 file_path = Path (file_path )
1617 if file_path .is_file () and file_path .exists ():
1718 try :
18- shutil .copy2 (file_path , target_path )
19+ if copy_metadata :
20+ shutil .copy2 (file_path , target_path )
21+ else :
22+ shutil .copy (file_path , target_path )
1923 file_automation_logger .info (f"Copy file origin path: { file_path } , target path : { target_path } " )
2024 return True
2125 except shutil .Error as error :
@@ -25,17 +29,19 @@ def copy_file(file_path: str, target_path: str) -> bool:
2529 return False
2630
2731
28- def copy_specify_extension_file (file_dir_path : str , target_extension : str , target_path : str ) -> bool :
32+ def copy_specify_extension_file (
33+ file_dir_path : str , target_extension : str , target_path : str , copy_metadata : bool = True ) -> bool :
2934 """
3035 :param file_dir_path: which dir do we want to search
3136 :param target_extension: what extension we will search
3237 :param target_path: copy file to target path
38+ :param copy_metadata: copy file metadata or not
3339 :return: True if success else False
3440 """
3541 file_dir_path = Path (file_dir_path )
3642 if file_dir_path .exists () and file_dir_path .is_dir ():
3743 for file in file_dir_path .glob (f"**/*.{ target_extension } " ):
38- copy_file (str (file ), target_path )
44+ copy_file (str (file ), target_path , copy_metadata = copy_metadata )
3945 file_automation_logger .info (
4046 f"Copy specify extension file on dir"
4147 f"origin dir path: { file_dir_path } , target extension: { target_extension } , "
0 commit comments