import sys, os
root = r"C:\py\results\csv" # внутри другие папки с csv-файлами
for path, subdirs, files in os.walk(root):
with open(os.path.join(path, "output.cvs"), 'w') as f:
for name in files:
if not name.endswith(".cvs"): continue
csvfile = os.path.join(path, name)
with open(csvfile, 'r') as file:
for url in file:
f.write(url + "\n")
# Функция для записи строк в один файл для каждой папки
#def writecsv(url, filename):
# with open(filename + '.csv', 'a') as f:
# f.write(url + "\n")