以编程方式检查驱动器号是否为共享/网络驱动器

Phi*_*ier 11 python winapi network-drive drive-letter

有没有办法检查驱动器号是否代表共享驱动器/网络驱动器或python中的本地光盘?我想有一些Windows api函数给了我这些信息,但我找不到它.也许甚至已经在python中集成了一种方法?

我正在寻找的是具有这种或类似行为的东西:

someMagicMethod("C:\\")  #outputs True 'is a local drive'
someMagicMethod("Z:\\")  #outputs False 'is a shared drive'
Run Code Online (Sandbox Code Playgroud)

这对我也有帮助:

someMagicMethod2()  #outputs list of shared drive letters
Run Code Online (Sandbox Code Playgroud)

ano*_*ard 13

模块中的GetDriveType函数win32file可以帮助您 - 它是GetDriveType WINAPI函数的包装器.

import win32file
isNetworkDrive = win32file.GetDriveType("Z:\\") == win32file.DRIVE_REMOTE
Run Code Online (Sandbox Code Playgroud)

您可以使用模块中的GetLogicalDriveStrings()函数枚举所有函数win32api,然后使用循环仅选择网络驱动器.