Python file copier
import shutil
import os
#Get source and destination folder paths from user input source folder = input("Enter the source folder path: ") destination folder = input("Enter the destination folder path: ")
# Check if the destination folder exists, and create it if it doesn't if not os.path.exists(destination_folder):
os.makedirs(destination_folder)
#Get a list of files in the source folder
files = os.listdir(source_folder)
#Iterate through the files and copy them to the destination folder for file in files:
source_file_path = os.path.join(source_folder, file) destination_file_path = os.path.join(destination_folder, file)
#Check if the file is a regular file (not a directory)
if os.path.isfile(source_file_path):
Copy the file to the destination folder
shutil.copy(source file path, destination_file_path) print('Copiad: (source file path) to (destination_file_path)')
print("Files copied successfully.')
Comments
Post a Comment