简体   繁体   English

在Windows上使用UNC路径获取文件列表

[英]get a List of files using UNC path on windows

I am trying to use Python 3 to list folders located on a Windows share drive. 我正在尝试使用Python 3列出位于Windows共享驱动器上的文件夹。 I have mounted the share in Windows explorer and I can clearly see the files exists 我已经在Windows资源管理器中安装了共享,我可以清楚地看到文件存在

I am using the following code: 我使用以下代码:

path = r'//UNCpath/subfolder1/subfolder2/subfolder3/'
for root, dirs, files in os.walk(path):
    print(root, dirs)
print('Hello')

but in the debugger, when I step over the for loop, it goes straight to the print('Hello') as if os.walk not finding anything. 但是在调试器中,当我跳过for循环时,它会直接进入print('Hello'),好像os.walk没有找到任何东西。 I don't get any error messages. 我没有收到任何错误消息。

please let me know what I am missing, or if creds are needed. 请让我知道我错过了什么,或者是否需要信用。

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

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

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