[英]Find same file name in different folders, and utilize two files for a certain task in python
There are folders in different folders like below不同文件夹中有文件夹如下
folder 1 - a, b, c...
folder 2 - a, b, c ...
And each folder has files with similar names like below每个文件夹都有类似名称的文件,如下所示
folder 1 - a - one.csv, two.csv,...
folder 2 - a - one_pred.csv, two_pred.csv,...
I would like to check files in each folder and when it finds same folder, go into the folder and when it finds one.csv & one_pred.csv
for instance,我想检查每个文件夹中的文件,当它找到相同的文件夹时,go 进入文件夹,当它找到one.csv & one_pred.csv
时,例如,
It goes to the ML performance check function它转到 ML 性能检查 function
rms = get_rms(one, one_pred)
But I'm not sure how to loop through two different folder at the same time and pass them to the function.但我不确定如何同时遍历两个不同的文件夹并将它们传递给 function。
I tried我试过了
folders = os.listdir(folder1)
for d in folders:
files = os.listdir(folder1 + d)
for f in files:
if f.split('_')[-1] == 'pred':
f_truth = f.replace('_pred','')
rms = get_rms(f_truth, f)
It didn't work.它没有用。 I thought this was wrong before I ran it, but I had no idea what I should do differently...在我运行它之前我认为这是错误的,但我不知道我应该做些什么不同......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.