开发者

Programmatically check whether a drive letter is a shared/network drive

开发者 https://www.devze.com 2022-12-28 13:04 出处:网络
Is there a way to check whether a drive letter stands for a shared drive/network drive or a local disc in python? I guess there is some windows api function that gives me that info, but I can\'t find

Is there a way to check whether a drive letter stands for a shared drive/network drive or a local disc in python? I guess there is some windows api function that gives me that info, but I can't find it. Perhaps there is even a method already integrated in python?

What I am 开发者_Go百科looking for is something with this or similar behaviour:

someMagicMethod("C:\\")  #outputs True 'is a local drive'
someMagicMethod("Z:\\")  #outputs False 'is a shared drive'

That would help me as well:

someMagicMethod2()  #outputs list of shared drive letters


The GetDriveType function in win32file module may help you - it's a wrapper for the GetDriveType WINAPI function.

import win32file
isNetworkDrive = win32file.GetDriveType("Z:\\") == win32file.DRIVE_REMOTE

You'd be able to enumerate all with the GetLogicalDriveStrings() function in the win32api module, then use a loop to pick out only the network drives.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号