# Import the necessary modules import os import shutil
# Define the file path to the source directory filePath="/Users/sandy/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat/2.0b4.0.9/e5935df9a7a640bff14105be4661fcb4/Message/MessageTemp"
# Get a list of files in the source directory get_files_sourceDir = os.listdir(filePath)
# Iterate over each file in the source directory
for file_sourceDir in get_files_sourceDir: # Define the path to the file within the source directory file_source = filePath+"/"+file_sourceDir+"/File"
# Check if the file exists if os.path.exists(file_source): # Get a list of files in the file_source directory get_files = os.listdir(file_source)
# Iterate over each file in the file_source directory for file_ in get_files: # Define the source and destination file paths src_file = os.path.join(file_source, file_) dst_file = os.path.join(dst_dir, file_) # Check if the destination file exists if os.path.exists(dst_file): # Check if the source and destination files are the same if os.path.samefile(src_file, dst_file): # If they are the same, skip this iteration of the loop continue # If they are not the same, remove the destination file os.remove(dst_file) # Move the file from the source directory to the destination directory shutil.move(file_source + "/" + file_, dst_dir) # Print the name of the file that was moved print(file_) else: # If the file does not exist, print an error message print("The file does not exist")