Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: file system iteration

Reply
Thread Tools

RE: file system iteration

 
 
Tim Golden
Guest
Posts: n/a
 
      10-09-2006
[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.../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
__________________________________________________ ______________________
 
Reply With Quote
 
 
 
 
Rob Williscroft
Guest
Posts: n/a
 
      10-09-2006
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.../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/
 
Reply With Quote
 
 
 
 
rick
Guest
Posts: n/a
 
      10-09-2006
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.
 
Reply With Quote
 
rick
Guest
Posts: n/a
 
      10-09-2006
Thanks Tim and Rob... this works really well!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Iteration through File.file? misses entries for whichFile.file?(entry) == true Kyle Barbour Ruby 10 08-02-2010 08:55 PM
Struts - Problem with nested iteration or double iteration Rudi Java 5 10-01-2008 03:30 AM
file system iteration rick Python 10 10-09-2006 05:55 PM
iteration through a file of structs Dennis Schulz C Programming 2 05-08-2004 08:13 PM
open new file each loop iteration Danny Anderson C++ 0 01-21-2004 08:56 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57