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))
I call the function accordingly:
format_drive('F:\\', 'NTFS', 'USBDrive')
And the program prints this:
>>>
9
11
I found the solution! This line:
FMIFS_HARDDISK = 0x0C
should be like this
FMIFS_UNKNOWN = 0
That simply makes it format by Unknown!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With