Copy a file or directory. Args: src: The path to the file or directory. dest: The path to the destination. overwrite: Whether to overwrite the destination. Returns: Whether the copy was successful.
(src: str, dest: str, overwrite: bool = True)
| 30 | |
| 31 | |
| 32 | def cp(src: str, dest: str, overwrite: bool = True) -> bool: |
| 33 | """Copy a file or directory. |
| 34 | |
| 35 | Args: |
| 36 | src: The path to the file or directory. |
| 37 | dest: The path to the destination. |
| 38 | overwrite: Whether to overwrite the destination. |
| 39 | |
| 40 | Returns: |
| 41 | Whether the copy was successful. |
| 42 | """ |
| 43 | if src == dest: |
| 44 | return False |
| 45 | if not overwrite and os.path.exists(dest): |
| 46 | return False |
| 47 | if os.path.isdir(src): |
| 48 | rm(dest) |
| 49 | shutil.copytree(src, dest) |
| 50 | else: |
| 51 | shutil.copyfile(src, dest) |
| 52 | return True |
| 53 | |
| 54 | |
| 55 | def mv(src: str, dest: str, overwrite: bool = True) -> bool: |