我想对子目录中的所有文件执行一个操作,并将out放入另一个目录。例如,在/Pictures/中有subdirs/一月、/二月等,其中有imgages。我想对图像执行操作,并将输出放到/Processed/及其子目录/January、/Februady等
我想这样的问题可以解决,但我真的需要一些帮助:
import os
path = '/Pictures/'
outpath = '/Processed/'
for subdir, dirs, files in os.walk(path):
#do something with files and send out put to corresponding output dir
这基本上是遍历一个目录的所有文件夹,得到它的文件;使用
performFunction()
执行一些操作并写入同一个文件您可以修改它以写入不同的路径强>希望有帮助
这将为您提供基本结构:
它在
'Processed/'
中创建与'Pictures/'
中相同的子文件夹结构,并对每个文件名进行迭代对于文件夹中的每个文件,都会得到
new_path
变量:old_path
是'Pictures/1/test.jpg'
,new_path
将是'Processed/1/test.jpg'
相关问题 更多 >
编程相关推荐