[英]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.