使用Python 2.7对USB驱动器进行分区和格式化

时间:2017-07-28 14:55:17

标签: python python-2.7 formatting usb partitioning

有没有办法多次对USB驱动器进行分区,并使用Python 2.7.x将每个分区格式化为不同的类型?

编辑:使用Windows 7作为操作系统

1 个答案:

答案 0 :(得分:0)

如评论中所述,您可以在Windows命令行工具中使用python subprocess。可以使用format

完成格式化

Running windows shell commands with python&lt; - 你也可以使用diskpart <)>

对于分区,您可以将diskpart工具与批处理文件结合使用。缺点是您必须将批处理文件保存在计算机上

https://social.technet.microsoft.com/Forums/windows/en-US/c69d3bb5-328c-43e3-9239-837171e42b88/diskpart-batch-file?forum=w7itproinstall

使用以下命令可以从python

调用批处理文件
from subprocess import Popen
p = Popen("batch.bat", cwd=r"C:\Path\to\batchfolder")
stdout, stderr = p.communicate()

Run a .bat file using python code

相关问题