very强烈的小病毒
- 游戏开发
- 2025-08-27 00:36:02

#python import os import subprocess
def format_drive(drive_letter): try: # 检查驱动器是否存在 if not os.path.exists(drive_letter + ":\\"): print(f"驱动器 {drive_letter}: 不存在") return
# 使用diskpart命令格式化驱动器 script = f""" select volume {drive_letter} format fs=ntfs quick exit """ # 将脚本写入临时文件 with open("format_script.txt", "w") as f: f.write(script) # 执行diskpart命令 subprocess.run(["diskpart", "/s", "format_script.txt"], check=True) print(f"驱动器 {drive_letter}: 格式化完成") except subprocess.CalledProcessError as e: print(f"格式化失败: {e}") finally: # 删除临时脚本文件 if os.path.exists("format_script.txt"): os.remove("format_script.txt")
if __name__ == "__main__": drive_letter = input("请输入要格式化的驱动器字母(例如 C、D 等): ").strip().upper() format_drive(drive_letter)
### 注意事项: 1. **数据丢失**:格式化操作会永久删除驱动器上的所有数据,请务必提前备份重要文件。 2. **权限**:运行此脚本需要管理员权限。 3. **测试**:在实际使用前,建议在虚拟机或测试环境中进行测试。 4. **操作系统**:此脚本适用于Windows系统,因为它使用了`diskpart`工具。
### 使用方法: 1. 将上述代码保存为一个Python文件,例如`format_drive.py`。 2. 以管理员身份运行命令提示符或PowerShell。 3. 运行脚本并输入要格式化的驱动器字母。
### 示例: python format_drive.py
输入驱动器字母(例如 `C`),脚本将尝试格式化该驱动器。
再次强调,格式化操作是不可逆的,请谨慎使用。
very强烈的小病毒由讯客互联游戏开发栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“very强烈的小病毒”