def scan_and_copy(self): """ 扫描待整理的文件目录,要任务是打包目录或者更新文件名,然后复制到目标目录 :return: 无返回值 """ packed = set() special_path = set() # 利用os.walk函数遍历文件夹 for path, _, files in os.walk(self.__dirty_path.absolute_path): path_obj = Path(path,self.__dirty_path.absolute_path) skipped = False # 检验是否是打包目录下的子目录,如果是,那么略过 for packed_item in packed: if path_obj.is_child_of(packed_item.absolute_path): skipped = True break if skipped: continue if path_obj.parser.is_packed: self._to_be_moved.append(path_obj.compress()) packed.add(path_obj) continue # 对于具有特殊字符的目录进行处理 if path_obj.parser.is_having_special_character: files = path_obj.append_file_suffix(path_obj.parser.special_character_part) self._to_be_moved.extend([File(file) for file in files]) packed.add(path_obj) special_path.add(path_obj) continue self._to_be_moved.extend([File(os.path.join(path,file)) for file in files]) # 把待移动的文件复制到指定的目录 for file_moved in self._to_be_moved: print(file_moved.parser.path_name) destination_path = self.__clean_path.find_one(file_moved.parser.dirs) if destination_path is None: print('Can not find the destination path!') raise FileNotFoundError OSOperator.copy_to(file_moved.parser.path_name_with_absolute_path,destination_path.absolute_path) # 移除原有路径中具有特殊字符路径下文件的特殊字符后缀 for sp in special_path: sp.remove_append_file_suffix()
def find_and_open(self, base_path, temp_path, **condition): """ 根据condition条件查询filedb数据库,复制查询得到的文件到temp_path,并且打开temp_path文件窗口 :param str base_path: :param str temp_path: :param dict condition: :return: 返回成功或失败信息 :rtype: str """ result = list(self.collection.find(condition)) if len(result) < 1: return "None is found!" else: for item in result: source_file = os.path.join(base_path, item["full_file_name"]) destination_file = os.path.join(temp_path, item["file_name"]) OSOperator.copy_to(source_file, destination_file) os.startfile(temp_path) return "successfully!"