Posts

Showing posts from September, 2023

mod

 import shutil import os # Function to move files from source to destination def move_files(source_folder, destination_folder):     # Ensure the source folder exists     if not os.path.exists(source_folder):         print("Source folder '%s' does not exist." % source_folder)         return     # Ensure the destination folder exists; create it if not     if not os.path.exists(destination_folder):         os.makedirs(destination_folder)     # Get a list of all files in the source folder     files = os.listdir(source_folder)     # Loop through the files and move them to the destination folder     for file in files:         source_path = os.path.join(source_folder, file)         destination_path = os.path.join(destination_folder, file)         # Use shutil.move to move the file   ...

new

 import shutil import os # Function to move files from source to destination def move_files(source_folder, destination_folder):     # Ensure the source folder exists     if not os.path.exists(source_folder):         print(f"Source folder '{source_folder}' does not exist.")         return     # Ensure the destination folder exists; create it if not     if not os.path.exists(destination_folder):         os.makedirs(destination_folder)     # Get a list of all files in the source folder     files = os.listdir(source_folder)     # Loop through the files and move them to the destination folder     for file in files:         source_path = os.path.join(source_folder, file)         destination_path = os.path.join(destination_folder, file)         # Use shutil.move to move the file    ...

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.')