Python: Get Mount Point on Windows or Linux

后端 未结 3 1064
说谎
说谎 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:28

    Here is some code to return the UNC path pointed to by a drive letter. I suppose there is a more slick way to do this, but I thought I'd contribute my small part.

    import sys,os,string,re,win32file
    for ch in string.uppercase:  # use all uppercase letters, one at a time
        dl = ch + ":"
        try:
            flds = win32file.QueryDosDevice(dl).split("\x00")
        except:
            continue
        if re.search('^\\\\Device\\\\LanmanRedirector\\\\',flds[0]):
            flds2 = flds[0].split(":")
        st = flds2[1]
        n = st.find("\\")
        path = st[n:] 
            print(path)
    

提交回复
热议问题