【问题标题】:Python 3.X : rglob with FileNotFoundError: [WinError 3] The system cannot find the path specifiedPython 3.X : rglob with FileNotFoundError: [WinError 3] 系统找不到指定的路径
【发布时间】:2020-06-03 00:14:25
【问题描述】:

我正在使用 glob 遍历目录,并提取适合特定参数的文件。我遇到的问题是全局中的 FileNotFoundError:

def collate_files(old_dir, new_dir) -> str:
   for subfolder in old_dir.rglob('*.xlsx'):  
       if subfolder.match("string_title"):
           new_dir= new_dir.joinpath(subfolder)
           if Path.exists(new_dir):
               pass
           else:
               try:
                   shutil.copy(subfolder, new_dir, follow_symlinks=True)
               except OSError as e:
                   raise e

错误出现:

FileNotFoundError: [WinError 3] The system cannot find the path specified: "\\\\absoute_path_directory\\subfolder\\etc"

我仔细检查了,文件路径存在。我该怎么做才能修复 OSError 或完全忽略它?

【问题讨论】:

    标签: python-3.x list glob


    【解决方案1】:

    这可能是您的文件路径长度的问题?常规 DOS 路径仅限于 MAX_PATH (260) 个字符。因此,您可以查看下面的链接以获取详细信息。最好的方法是在 glob 中激活长路径支持。但我不知道该怎么做。

    Pathname too long to open?

    os.stat FileNotFoundError [Win Error 3] when file exist. (Python)

    【讨论】:

      猜你喜欢
      • 2018-12-03
      • 2020-01-29
      • 2022-01-23
      • 2021-10-13
      • 2021-08-20
      • 2022-12-11
      • 2023-01-25
      • 1970-01-01
      • 2022-11-17
      相关资源
      最近更新 更多