使用 pathlib glob 提取文件名以 0/ 1 开头的路径的模式
Pattern for extracting paths where filename starts with 0/ 1 using pathlib glob
我尝试在 pathlib glob
中使用普通 python regex patterns
,但它不起作用。
在网上阅读时,我开始知道 glob 模式非常不同。
我没有在网上找到我要找的图案。
我有:
一个名为 images
的文件夹,例如:
from pathlib import Path
print(list(Path('./images').glob("*")))
给出:
[WindowsPath('images/01.jpg'),
WindowsPath('images/11.jpg'),
WindowsPath('images/010.jpg'),
... ]
我希望 glob 仅提取名称 以 0 开头的图像,例如 01.jpg
& 010.jpg
& 而不是 11.jpg
实现这一目标的模式是什么!
尝试使用 pathlib's iterdir
和 startswith
p = Path('./images')
for pth in p.iterdir():
if pth.name.startswith('0'):
print(pth)
images/01.jpg
images/010.jpg
我尝试在 pathlib glob
中使用普通 python regex patterns
,但它不起作用。
在网上阅读时,我开始知道 glob 模式非常不同。
我没有在网上找到我要找的图案。
我有:
一个名为 images
的文件夹,例如:
from pathlib import Path
print(list(Path('./images').glob("*")))
给出:
[WindowsPath('images/01.jpg'),
WindowsPath('images/11.jpg'),
WindowsPath('images/010.jpg'),
... ]
我希望 glob 仅提取名称 以 0 开头的图像,例如 01.jpg
& 010.jpg
& 而不是 11.jpg
实现这一目标的模式是什么!
尝试使用 pathlib's iterdir
和 startswith
p = Path('./images')
for pth in p.iterdir():
if pth.name.startswith('0'):
print(pth)
images/01.jpg
images/010.jpg