Hi
I have python code that can list all drive letters but now I need also list the name of drive letter (Label) and the size of hard drive like below!

      Ltr    Label                   Size        
    ----  ------                  ---------  
     C       Windows              800 GB     
     E      Local Disk           200 GB  
     F       My Passport          500 GB
     Y        Secret               1 GB

import string
from ctypes import windll

def get_drives():
    drives = []
    bitmask = windll.kernel32.GetLogicalDrives()
    for letter in string.ascii_uppercase:
        if bitmask & 1:
            drives.append(letter)
        bitmask >>= 1

    return drives

if __name__ == '__main__':
    print (get_drives())    # On my PC, this prints ['A', 'C', 'D', 'F', 'H']

OR This code

import os
print (os.popen("fsutil fsinfo drives").readlines())

How can I do it ?
I appreciate your help really

Any helps?

This question has other priors. My point here is it won't be OS agnostic if you do this. You would need versions for Apple OS, Windows, Linux and so on. What's wrong with the call to diskpart and parsing the result? It's a quick hack and done. Also, research the web for more ideas but as you'll find out "this is a bad idea."

rproffitt
I have a carving python script which is carve jpg file from dd image
I will do some changing that the script carving file direct from driver
I must know the list of drivers so that I can run script against specific drive
My forensic python script search after JPG Header and Footer (0xFFD8 and 0xFFD9)

I can't guess why this is required but sure, find the OS command that gets you that detail then put that in your os....() function with some redirect to a text file which you can parse.

What I see in your last reply is something about forensics. In the forensics work I've done we are not afraid to use the command line to get the information for the report.

rproffitt,
Is it possible show me your code to see how you think?

It's the link I supplied. And that changes for each OS you add support for. This is why this is a bad idea.

Thanks rproffitt for your reply