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

发布于 2024-08-31 08:10:37 字数 377 浏览 4 评论 0原文

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

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

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

这也会对我有帮助:

someMagicMethod2()  #outputs list of shared drive letters

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 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

時窥 2024-09-07 08:10:37

win32file 模块中的 GetDriveType 函数可能会帮助您 - 它是 GetDriveType WINAPI 函数。

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文