python - 遍历目录,删除

标签 python

我想遍历给定目录 e://www/files/delivery 及其所有子目录,并删除所有以 _thumb.jpg 结尾的图像。

到目前为止我尝试了什么:

import os

dir='e:\www\files\delivery'

for root, dirs, files in os.walk(dir):
  for name in files:
    if name.endswith(("_thumb.jpg")):
      os.remove(name?)....

显然这不起作用。

此外,如果我想使用 python wand library 调整所有图像的大小而不是删除它们,是否是相同的过程?

最佳答案

import os

dir='e:\www\files\delivery'

for root, dirs, files in os.walk(dir):
  for name in files:
    if name.endswith(("_thumb.jpg")):
      os.remove(os.path.join(root, name))

关于python - 遍历目录,删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18540347/

相关文章:

python - Django 不解析自定义的 http 接受 header

java - Python/C++/Java : Is there a library that will recognize characters and tell me where they are in an image?

python - Python 中的 SVD 内存错误

python - CVLIB-如何为原始图像添加模糊的子表面?

python - 使用 grep 或 awk 从 python 文件中提取文档字符串

python - 这个 TF 训练曲线是过拟合还是欠拟合?

python - 使用 Python 中的二分搜索进行猜谜游戏

python - 如何将列表分成相等的部分?

Python Flask SQLalchemy 外键未保存在数据库中 - 一对多

python - 如何使用matplotlib将节点数一一相加然后显示