windows directory

Peter Hansen peter at engcorp.com
Tue Jun 14 07:58:12 EDT 2005


Richard Lewis wrote:
> If you want to know where a particular directory is (on a Windows
> 'drive') you could use:
> 
> for drive_label in ["C", "D"]:
>     if "Program Files" in os.listdir(drive_label + ":/"): return
>     drive_label

This would cause trouble in at least two cases that I've seen.  One was 
a multiboot machine that had Windows 2000 on D: and Windows XP on C:. 
The other was a machine that had the Program Files folder copied, for 
reasons I don't recall (and perhaps only temporarily), to the D: drive.

Use one of the defined APIs for getting this information, not a hack 
like this please.

-Peter



More information about the Python-list mailing list