I have been trying to make a python file that will copy contents from one folder to another. I would like it to work on any Windows system that I run it on. It must copy ALL things ...
i need solution to this problem.
I have been trying to make a python file that will copy contents from one folder to another. I would like it to work on any Windows system that I run it on. It must copy ALL things ...
i need solution to this problem.
import shutil
import os
# Path to the directory
source = 'C:/path/to/source/folder'
# Path to the destination directory
destination = 'C:/path/to/destination/folder'
# Copy contents from source to destination
shutil.copytree(source, destination)
# List all the files in source directory
source_files = os.listdir(source)
# Iterate over all the files in source directory
for file_name in source_files:
# Create full path of file in source directory
full_file_name = os.path.join(source, file_name)
# If file is a directory, create corresponding directory in destination
# directory
if os.path.isdir(full_file_name):
shutil.copytree(full_file_name, os.path.join(destination, file_name))
else:
# Copy the file from source to destination
shutil.copy2(full_file_name, destination)
import shutil
import os
source = 'C:/path/to/source/folder'
destination = 'C:/path/to/destination/folder'
shutil.copytree(source, destination)
source_files = os.listdir(source)
for file_name in source_files:
full_file_name = os.path.join(source, file_name)
if os.path.isdir(full_file_name):
shutil.copytree(full_file_name, os.path.join(destination, file_name))
else:
shutil.copy2(full_file_name, destination)