How to get the map between disk volume label and drive in python

Viewed 230

I'm trying to get the map between disk volume and drive in python but failed in any SO thread. It's quite easy to implement it in java, as the sample below:

import java.io.File;
import javax.swing.filechooser.FileSystemView;
public class Test{

    public void listMap(){
        File[] files = File.listRoots();
        System.out.println("The map between volume label and drive is: " );
        for(File file: files){
            String theMap = FileSystemView.getFileSystemView().getSystemDisplayName(file);
            System.out.println(theMap);
        }
    }

    public static void main(String[] args) {
        Test test = new Test();
        test.listMap();
    }
}

The map between volume label and drive is:

2008x64 (C:)
FlashDisk (E:)

If the map is there, it's quite easy to get drive "C:" based on the volume label "(2008x64)" and vice versa.

Thanks for your help in advance.

1 Answers

You might be looking for the win32api GetVolumeInformation method.

In [3]: win32api.GetVolumeInformation('c:\\')
Out[3]: ('', -697410715, 255, 65471231, 'NTFS')

Where '' would be the label (except my c drive is unlabeled).

Related