Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Python (http://www.programmingforums.org/forum43.html)
-   -   Listing HD's (http://www.programmingforums.org/showthread.php?t=15841)

Freaky Chris May 18th, 2008 5:37 AM

Listing HD's
 
Hey, i was wondering if anybody could point in the right direction. Ie give me the name of modules and links to module listing etc for a method of listing what HD's a computer, under WinXP.

Thanks,
Chris

Freaky Chris May 18th, 2008 3:23 PM

Re: Listing HD's
 
Is there a way of doing this properly or would i have to do something like this

:

  1. drives = ["A:\\", "B:\\", "C:\\", "D:\\", "E:\\", "F:\\", "G:\\", "H:\\", "I:\\", "J:\\", "K:\\", "L:\\", "M:\\", "N:\\", "O:\\", "P:\\", "Q:\\", "R:\\", "S:\\", "T:\\", "U:\\", "V:\\", "W:\\", "X:\\", "Y:\\", "Z:\\"]
  2. for drive in drives:
  3.         if os.path.exists(drive):
  4.                 print drive, "Present"
  5.         else:
  6.                 print drive, "Not Present"


So is that how i will have to do it, or is there an actual method to do that for you?

Chris

iEngage May 18th, 2008 3:51 PM

Re: Listing HD's
 
well I don't have a solution for you, but one thing worth mentioning about the way you have it done is this: every single drive that has a letter will be shown as present. This includes mapped drives, optical drives etc.

EDIT: I found the below link that may help, but it seems as if you have to have a 3rd party module to do it, because when i tried it it gave an error about win32file

http://mail.python.org/pipermail/pyt...ay/324479.html

Also instead of listing out all the drives like that in one huge array, you could just do the following if you like it better:

:

  1. import os,string
  2.  
  3. for drive in string.ascii_uppercase:
  4.         if os.path.exists(drive+":"):
  5.                 print drive+":", "Present"
  6.         else:
  7.                 print drive+":", "Not Present"


Freaky Chris May 18th, 2008 4:04 PM

Re: Listing HD's
 
Indeed this is a 3rd party module which is not what im after, and yes im aware that the solution i use will show all drives, this is in actual fact how i would like it. You have to bare in mind in only shows drives in use not blank CD drives etc. And again mapped network drives are also wanted.

Chris

iEngage May 18th, 2008 4:13 PM

Re: Listing HD's
 
well then in that case your solution seems to be the way to go

Freaky Chris May 18th, 2008 4:16 PM

Re: Listing HD's
 
yes and ising string is the better option, i don't know why i didn't do that in the first place lol. O well thanks for reminding me. i May look int WMI (although it is an extra module) aparently has some functionality that could be of use to me.

Chris

iEngage May 18th, 2008 4:25 PM

Re: Listing HD's
 
Quote:

Originally Posted by Freaky Chris (Post 145331)
O well thanks for reminding me.

no problem :)

kruptof May 18th, 2008 4:48 PM

Re: Listing HD's
 
Not a python person but a quick google turned up this

Hope it helps

Freaky Chris May 18th, 2008 4:57 PM

Re: Listing HD's
 
Yer its another example of a third party module by the looks of it, or at least a module that is no longer supported. I'd rather use default libraries and working with the solution i have at the moment since i would like to be able to rn the script on other machines that will not have the extra modules installed.

But thanks anyway, these were the sorts of things i was getting when i googled it myself.

Chris

Game_Ender May 20th, 2008 10:28 AM

Re: Listing HD's
 
I wouldn't stop there at all. Take a look at the source code for those 3rd party modules. Its most likely that they use the Win32 API (or another C api). If so you can use ctypes to just load the right DLL and call the needed functions directly from Python. No 3rd party module is needed. I have done this myself for other areas of Win32 API and it works just fine.


All times are GMT -5. The time now is 4:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC