繁体   English   中英

检查网络驱动器是否在python中连接?

[英]Checking if network drive is connected in python?

我想在 Windows (7) 上运行的 python 脚本中验证网络驱动器已连接且可用。 我会做类似以下的事情:

import os
connection_works = os.path.exists("F:\\")

但是,这似乎只是在连接关闭时挂起,在重新建立连接时返回 True。 使用 glob(我的下一个想法)表现出相同的行为。 这样做的聪明方法是什么?

您只是将 os.path.exists() 的输出保存到 connection_works 中。 尝试类似:

if os.path.exists("F:\\"):
    print('path exists'):
else:
    print('path does not exists):

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM