【发布时间】:2021-07-18 22:42:34
【问题描述】:
我有一个包含很多子文件夹的文件夹,每个文件夹中都保存为 png 格式的图片:
例如:
emotion\angry
emotion\disgusted
emotion\fearful
emotion\happy
我可以使用以下代码删除其中一个文件夹中的图像:
folder_path = (r'C:\Users\emotion\angry')
test = os.listdir(folder_path)
for images in test:
if images.endswith(".png"):
os.remove(os.path.join(folder_path, images))
我如何创建一个循环来遍历emotion/中的每个子文件夹? 因为我不想手动写出所有代码来清除所有文件夹...
【问题讨论】:
标签: python loops operating-system