【问题标题】:get a List of files using UNC path on windows在 Windows 上使用 UNC 路径获取文件列表
【发布时间】:2019-04-16 19:32:00
【问题描述】:

我正在尝试使用 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 没有找到任何东西一样。我没有收到任何错误消息。

请让我知道我缺少什么,或者是否需要信用。

【问题讨论】:

标签: python


【解决方案1】:

我有同样的错误,你说的是正确的,它没有找到路径,下面的代码是我作为一个可以工作的半项目制作的,并且与你的相关: 我把它作为一个输入函数,这样你就可以找到一个特定的文件/文件夹

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

【讨论】:

  • 确保添加您的驱动器,因为您的问题中缺少该驱动器,即 c 驱动器或 h 驱动器。
  • 这很好,有时我的代码无法在另一台计算机上运行,​​很乐意提供帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多