Python: Get Mount Point on Windows or Linux

后端 未结 3 1045
说谎
说谎 2021-01-05 23:28

I need a function to determine if a directory is a mount point for a drive. I found this code already which works well for linux:

def getmount(path):
  path          


        
3条回答
  •  悲哀的现实
    2021-01-06 00:32

    Do you want to find the mount point or just determine if it is a mountpoint?

    Regardless, as commented above, it is possible in WinXP to map a logical drive to a folder.

    See here for details: http://www.modzone.dk/forums/showthread.php?threadid=278

    I would try win32api.GetVolumeInformation

    >>> import win32api
    >>> win32api.GetVolumeInformation("C:\\")
        ('LABEL', 1280075370, 255, 459007, 'NTFS')
    >>> win32api.GetVolumeInformation("D:\\")
        ('CD LABEL', 2137801086, 110, 524293, 'CDFS')
    >>> win32api.GetVolumeInformation("C:\\TEST\\") # same as D:
        ('CD LABEL', 2137801086, 110, 524293, 'CDFS')
    >>> win32api.GetVolumeInformation("\\\\servername\\share\\")
        ('LABEL', -994499922, 255, 11, 'NTFS')
    >>> win32api.GetVolumeInformation("C:\\WINDOWS\\") # not a mount point
        Traceback (most recent call last):
        File "", line 1, in 
        pywintypes.error: (144, 'GetVolumeInformation', 'The directory is not a subdirectory of the root directory.')
    

提交回复
热议问题