Movatterモバイル変換
[0]ホーム
drives in a file chooser
Ken Seehofkens at sightreader.com
Mon Apr 30 15:43:00 EDT 2001
Well, there's always brute force...>>> import os, string>>> def GetDrives():... drives = []... for a in string.lowercase:... if os.path.exists('%s:/'%a):... drives.append('%s:'%a)... return drives...>>> GetDrives()['a:', 'c:', 'd:', 'e:', 'i:', 'x:']----------------------------------------------------Copyright (c) 2001 by Ken SeehofThis document may not be distributed, copied,duplicated, or replicated, or duplicated in anyform without express permission by Ken Seehof.Permission is hereby granted.kseehof at neuralintegrator.com--------------------------------------------------------- Original Message -----From: "Matt Setzer" <dontspamsetzer at nwlink.com>Newsgroups: comp.lang.pythonTo: <python-list at python.org>Sent: Sunday, April 29, 2001 10:21 PMSubject: Re: drives in a file chooser>> I don't think there's a way to do it from the os module, but if you've> got the win32 extensions installed this should do it :>> from win32file import GetLogicalDrives>> def GetDrives() :> "Returns a list of valid drives on this system, in order"> drives = []> driveMask = GetLogicalDrives()> for i in range( 0, 31 ) :> if driveMask & ( 1 << i ) :> drives.append( chr( ord( 'a' ) + i ) )>> return drives>> Matt Setzer>> "Volucris" <volucris at hotmail.com> wrote in message> news:3aecd342$0$39601$6e49188b at news.goldengate.net...> > Is there a way to get a list of the drives available (on win32: c:, a:,> b:,> > d:, etc.)? Ultimately, I want to make a file chooser in a Tkinter app.> > Desperatly I tried> >> > os.listdir(os.path.abspath('c:\\..'))> >> > but that does nothing useful. Otherwise, I could just confine my usersto> a> > single drive and say it's a security feature.> >> > greg> >> >>>> -->http://mail.python.org/mailman/listinfo/python-list>
More information about the Python-listmailing list
[8]ページ先頭