我正在尝试使用Python 3列出Windows共享驱动器上的文件夹。我已经在Windows资源管理器中挂载了共享,并且可以清楚地看到文件存在
我正在使用以下代码:
path = r'//UNCpath/subfolder1/subfolder2/subfolder3/'
for root, dirs, files in os.walk(path):
print(root, dirs)
print('Hello')
但是在调试器中,当我跨过for循环时,它直接进入print('Hello'),好像os.walk找不到任何东西。我没有收到任何错误消息。
请让我知道我在想什么,或者是否需要证明。
答案 0 :(得分:0)
I had the same error, what you said is correct, it is not finding the path, the code below is what I made as a semi project that works and is in correlation to yours: I made it as an input function so you can find a specific file/folder
s = input("Enter the directory you wish to visit")
rootdi = rootdir+"\\"
root = rootdi+s
print(root)
if os.path.isfile(root) is False:
print("No such directory")
quit()