Skip to content

move

Bases: FileOperation

Move files that match a patterns from source directory to target directory

Source code in file_operations/move.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class MoveOperation(FileOperation):
    """Move files that match a patterns from source directory to target directory """
    @staticmethod
    def add_arguments(settings: AppSettings, parser: argparse.ArgumentParser) -> None:
        parser.add_argument(Arguments.dst, help=HelpStrings.dst)
        pass

    def do_task(self):
        for file_path in self.files_for_task:
            if file_path.is_file() and file_path.parent.resolve() != self.target_directory.resolve():
                target_file_path = self.target_directory / file_path.name
                self.logger.info(f"{file_path} -> {self.target_directory}")

                try:
                    shutil.move(file_path, target_file_path)
                except Exception as e:
                    self.logger.error(e)