如何遍历目录并将两个文件名传递给我编写的另一个 python 程序或函数?
下面是我当前的脚本,它带有一些输出,它遍历一个目录并列出文件。我想一次将两个具有相同 8 个字符前缀的文件传递给我编写的另一个 python 程序或函数,它将这两个文件作为参数。
我需要在脚本中添加什么来添加此功能?
# Process 1. Iterate clean directory
os.chdir('/Applications/XAMPP/xamppfiles/htdocs/cleaned_files')
D = {}
fnames = os.listdir(".")
for fname in fnames:
print(fname)
date = fname[0:8] # this extracts the first 8 characters, aka: date
if date not in D:
D[date] = []
print D
上述脚本的输出
2012_06_Log.csv
2012_06_Summary.csv
2012_07_Log.csv
2012_07_Summary.csv
{'2012_07_': [], '2012_06_': []}