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

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',则无法恢复文件。

Python 代码恢复已删除文件

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

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