Formatting device from a script on Windows

V

volcano

Hello, folks!
Script I am creating has to format a device - USB flash drive. I have
tried using regular DOS "format" through "os.system" - did not work
well, because DOS format requires input from user. And the script
should run without user interference.
I have taken a look at ActivePython "win32..." libraries - did not find
anything.
Ideas? Pretty please?

Regards, Mark
 
W

weir

this may help, you need ctypes module.

##############################
from ctypes import *

fm = windll.LoadLibrary('fmifs.dll')

def myFmtCallback(command, modifier, arg):
print command
return 1 # TRUE

FMT_CB_FUNC = WINFUNCTYPE(c_int, c_int, c_int, c_void_p)


FMIFS_HARDDISK = 0x0C
fm.FormatEx(c_wchar_p('H:\\'), FMIFS_HARDDISK, c_wchar_p('NTFS'),
c_wchar_p('title'), True, c_int(0), FMT_CB_FUNC(myFmtCallback))
 
V

volcano

weir said:
this may help, you need ctypes module.

##############################
from ctypes import *

fm = windll.LoadLibrary('fmifs.dll')

def myFmtCallback(command, modifier, arg):
print command
return 1 # TRUE

FMT_CB_FUNC = WINFUNCTYPE(c_int, c_int, c_int, c_void_p)


FMIFS_HARDDISK = 0x0C
fm.FormatEx(c_wchar_p('H:\\'), FMIFS_HARDDISK, c_wchar_p('NTFS'),
c_wchar_p('title'), True, c_int(0), FMT_CB_FUNC(myFmtCallback))

Thanks for info, but somehow I am getting "invalid syntax" on this.
What could go wrong?
 
V

volcano

OK, it worked. Obviosly, quick format was a bad choice.

Thanks a lot for your help!
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top