gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
hi can u write python code to copy one file to another
- User
hi can u write python code to copy one file to another
- Assistant
Certainly! In Python, you can copy a file using the built-in
shutillibrary, which provides utilities for file operations. Below is a simple example of how to copy a file from one location to another:pythonimport shutil def copy_file(source, destination): try: shutil.copy(source, destination) print(f"File copied from {source} to {destination}") except FileNotFoundError: print(f"The file {source} was not found.") except Exception as e: print(f"An error occurred: {e}") # Example usage source_file = 'path/to/source/file.txt' # Replace with your source file path destination_file = 'path/to/destination/file.txt' # Replace with your destination file path copy_file(source_file, destination_file)