【发布时间】: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