Copy a single file with path, with checking and asking about the existence.
(source: Path, destination: Path)
| 3 | from pathlib import Path |
| 4 | |
| 5 | def copy_file(source: Path, destination: Path): |
| 6 | """ |
| 7 | Copy a single file with path, with checking and asking about the existence. |
| 8 | """ |
| 9 | if not source.is_file(): |
| 10 | print(f"Error: {source} is not a file.") |
| 11 | return |
| 12 | |
| 13 | if destination.exists(): |
| 14 | print(f"Warning: {destination.name} already exists in {destination.parent}.") |
| 15 | user_input = input(f"Do you want to overwrite {destination.name}? (y/n): ").strip().lower() |
| 16 | if user_input != 'y': |
| 17 | print(f"Skipping {destination.name}.") |
| 18 | return |
| 19 | |
| 20 | shutil.copy(source, destination) |
| 21 | print(f"Copied {source.name} to {destination}.") |
| 22 | |
| 23 | def copy_files_without_recursion(source: Path, destination): |
| 24 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected