使用Python格式化驱动器 [英] Format Drive in Python
问题描述
我正在尝试制作Python 3.3程序来格式化Windows中的驱动器,例如SD卡或USB记忆棒。我在这里尝试了以下代码: http://bytes.com/topic / python / answers / 537724-formatting-device-script-windows 。一开始它给了我一个错误,但经过一些调整后却没有。它运行了,但是我的USB驱动器没有任何反应。这是我正在使用的代码。 (这使用的是ctypes模块btw)请帮助!
I'm attempting to make a Python 3.3 program to format a drive in Windows such as a SD Card or USB Stick. I tried the code here: http://bytes.com/topic/python/answers/537724-formatting-device-script-windows. At first it gave me an error, but after some tweaking it didn't. It ran but nothing happened to my USB Drive. Here's the code I'm using. (This is using the ctypes module btw) Please Help!
def myFmtCallback(command, modifier, arg):
print(command)
return 1 # TRUE
def format_drive(Drive, Format, Title):
fm = windll.LoadLibrary('fmifs.dll')
FMT_CB_FUNC = WINFUNCTYPE(c_int, c_int, c_int, c_void_p)
FMIFS_HARDDISK = 0x0C
fm.FormatEx(c_wchar_p(Drive), FMIFS_HARDDISK, c_wchar_p(Format),
c_wchar_p(Title), True, c_int(0), FMT_CB_FUNC(myFmtCallback))
我相应地调用该函数:
format_drive('F:\\', 'NTFS', 'USBDrive')
程序将打印以下内容:
>>>
9
11
推荐答案
I找到了解决方案!这行:
I found the solution! This line:
FMIFS_HARDDISK = 0x0C
应该是这样的
FMIFS_UNKNOWN = 0
这简直就是用Unknown格式化!
That simply makes it format by Unknown!
这篇关于使用Python格式化驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!