Hi folks:
How can I get information regarding the drives in the system?, using Python, off course ;)
The information must include (at least in part) the following:

  • Size
  • Used space
  • Free space (although you can calculate this value from the former two, some systems are tricky and don't reveal the real thing)
  • File system
  • Label

The main issue about this task is that the solution must be preferable unix-like, but it will be better if the solution can be multiplatform.
Thanks in advance

The answer to this question really depends on what platform your developing for. There's no one answer that will work cross platform.

I haven't found an easy way to find all the information for Linux (other than looking through various configuration files, and the output of other programs). The os.statvfs is also very useful.

For Windows, you can use the WMI interface for python written by Tim Golden to find all this information. See: http://timgolden.me.uk/python/wmi_cookbook.html
for details.

Comments
Good info!

Or you can just run the 'list disk'


>>> f = open('listdiskcmd.txt', 'w')
>>> f.write('list disk')
>>> f.close()
>>> import os
>>> g = os.popen('diskpart /s listdiskcmd.txt > file.txt')
>>> g.close()
>>> h = open('file.txt', 'r')
>>> word = h.read()

>>> print word

Microsoft DiskPart version 5.1.3565

Copyright (C) ############################################
On computer: ############

Disk ### Status Size Free Dyn Gpt
-------- ---------- ------- ------- --- ---
Disk 0 Online 233 GB 0 B

This article has been dead for over six months. Start a new discussion instead.