RE: file system iteration

Discussion in 'Python' started by Tim Golden, Oct 9, 2006.

  1. Tim Golden

    Tim Golden Guest

    [Rick]
    | Searching for a file by name. Scanning for viruses. Etc.
    | There are lots
    | of legitimate reason to walk all paths from a central
    | starting point, no???

    Well, to get you started, I think this is the kind
    of thing you'll want. Uses ctypes, which is built-in
    to Python 2.5 so presumably legit.

    <code>
    import ctypes
    import string

    GetDriveType = ctypes.windll.kernel32.GetDriveTypeA

    for letter in string.uppercase:
    print letter, "=>", GetDriveType ("%s:" % letter)

    </code>

    You'll have to refer to

    http://windowssdk.msdn.microsoft.com/en-us/library/ms685874.aspx

    and various headers to get the values in question, but they
    look quite straightforward at a glance.

    TJG

    ________________________________________________________________________
    This e-mail has been scanned for all viruses by Star. The
    service is powered by MessageLabs. For more information on a proactive
    anti-virus service working around the clock, around the globe, visit:
    http://www.star.net.uk
    ________________________________________________________________________
    Tim Golden, Oct 9, 2006
    #1
    1. Advertising

  2. Tim Golden wrote in news:mailman.119.1160403292.11739.python-
    in comp.lang.python:

    > [Rick]
    >| Searching for a file by name. Scanning for viruses.
    > Etc.
    >| There are lots
    >| of legitimate reason to walk all paths from a centra
    > l
    >| starting point, no???
    >
    > Well, to get you started, I think this is the kind
    > of thing you'll want. Uses ctypes, which is built-in
    > to Python 2.5 so presumably legit.
    >
    > <code>
    > import ctypes
    > import string
    >
    > GetDriveType = ctypes.windll.kernel32.GetDriveTypeA
    >
    > for letter in string.uppercase:
    > print letter, "=>", GetDriveType ("%s:" % letter)
    >
    > </code>
    >
    > You'll have to refer to
    >
    > http://windowssdk.msdn.microsoft.com/en-us/library/ms685874.aspx
    >
    > and various headers to get the values in question, but they
    > look quite straightforward at a glance.
    >

    These seem to map when tested on my system:

    import ctypes

    DRIVE_TYPE_MAP = dict( enumerate ( """\
    DRIVE_UNKNOWN
    DRIVE_NO_ROOT_DIR
    DRIVE_REMOVABLE
    DRIVE_FIXED
    DRIVE_REMOTE
    DRIVE_CDROM
    DRIVE_RAMDISK
    """.split()
    ))

    ## if you need the constants ...
    for i, name in DRIVE_TYPE_MAP.iteritems():
    exec( "%s = %d" %( name, i) )

    GetDriveTypeW = ctypes.windll.kernel32.GetDriveTypeW
    for i in range( ord( 'A' ), 1 + ord('Z') ):
    path = u"%c:\\" % chr( i )
    print path, DRIVE_TYPE_MAP[ GetDriveTypeW( path ) ]

    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
    Rob Williscroft, Oct 9, 2006
    #2
    1. Advertising

  3. Tim Golden

    rick Guest

    Tim Golden wrote:
    > [Rick]
    > | Searching for a file by name. Scanning for viruses. Etc.
    > | There are lots
    > | of legitimate reason to walk all paths from a central
    > | starting point, no???
    >
    > Well, to get you started, I think this is the kind
    > of thing you'll want. Uses ctypes, which is built-in
    > to Python 2.5 so presumably legit.
    >
    > <code>
    > import ctypes
    > import string
    >
    > GetDriveType = ctypes.windll.kernel32.GetDriveTypeA
    >
    > for letter in string.uppercase:
    > print letter, "=>", GetDriveType ("%s:" % letter)
    >
    > </code>


    Thanks, I'll give this a try. I appreciate everyone's input.
    rick, Oct 9, 2006
    #3
  4. Tim Golden

    rick Guest

    Thanks Tim and Rob... this works really well!
    rick, Oct 9, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Danny Anderson

    open new file each loop iteration

    Danny Anderson, Jan 21, 2004, in forum: C++
    Replies:
    0
    Views:
    440
    Danny Anderson
    Jan 21, 2004
  2. Dennis Schulz

    iteration through a file of structs

    Dennis Schulz, May 8, 2004, in forum: C Programming
    Replies:
    2
    Views:
    340
    -berlin.de
    May 8, 2004
  3. rick

    file system iteration

    rick, Oct 9, 2006, in forum: Python
    Replies:
    10
    Views:
    489
    Duncan Booth
    Oct 9, 2006
  4. Rudi
    Replies:
    5
    Views:
    5,013
  5. Kyle Barbour
    Replies:
    10
    Views:
    584
    Marvin Gülker
    Aug 2, 2010
Loading...

Share This Page