Formatting device from a script on Windows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • volcano

    #1

    Formatting device from a script on Windows

    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

  • weir

    #2
    Re: Formatting device from a script on Windows

    this may help, you need ctypes module.

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

    fm = windll.LoadLibr ary('fmifs.dll' )

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

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


    FMIFS_HARDDISK = 0x0C
    fm.FormatEx(c_w char_p('H:\\'), FMIFS_HARDDISK, c_wchar_p('NTFS '),
    c_wchar_p('titl e'), True, c_int(0), FMT_CB_FUNC(myF mtCallback))

    Comment

    • volcano

      #3
      Re: Formatting device from a script on Windows


      weir wrote:
      this may help, you need ctypes module.
      >
      ############### ###############
      from ctypes import *
      >
      fm = windll.LoadLibr ary('fmifs.dll' )
      >
      def myFmtCallback(c ommand, modifier, arg):
      print command
      return 1 # TRUE
      >
      FMT_CB_FUNC = WINFUNCTYPE(c_i nt, c_int, c_int, c_void_p)
      >
      >
      FMIFS_HARDDISK = 0x0C
      fm.FormatEx(c_w char_p('H:\\'), FMIFS_HARDDISK, c_wchar_p('NTFS '),
      c_wchar_p('titl e'), True, c_int(0), FMT_CB_FUNC(myF mtCallback))
      Thanks for info, but somehow I am getting "invalid syntax" on this.
      What could go wrong?

      Comment

      • volcano

        #4
        Re: Formatting device from a script on Windows

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

        Thanks a lot for your help!
        Mark

        Comment

        Working...