恢复已删除的文件,可以使用以下代码:

import os
import shutil

def restore_deleted_file(file_path, restore_path):
    if os.path.exists(file_path):
        print("File already exists.")
        return
    
    try:
        shutil.move(restore_path, file_path)
        print("File restored successfully.")
    except FileNotFoundError:
        print("File not found.")
    except:
        print("Failed to restore file.")

# Example usage
file_path = "path_to_restored_file"  # 恢复后的文件路径
restore_path = "path_to_deleted_file"  # 已删除的文件路径
restore_deleted_file(file_path, restore_path)

请将file_path替换为要恢复的文件的路径,将restore_path替换为已删除文件的路径。如果文件已经存在于file_path,则无法恢复文件

恢复已删除的文件 的代码

原文地址: https://www.cveoy.top/t/topic/iAWG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录