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
shutil.move(source_path, destination_path)
print("Moved '%s' to '%s'" % (file, destination_folder))
print("All files have been moved.")
# Main program
if __name__ == "__main__":
# Prompt the user to enter source and destination folder paths
source_folder = raw_input("Enter the source folder path: ")
destination_folder = raw_input("Enter the destination folder path: ")
# Call the move_files function to move files
move_files(source_folder, destination_folder)
Comments
Post a Comment