I'm trying to take all files in a folder, join them and put their names in their rows so I can distinguish them. However, I get:
Traceback (most recent call last):
File "C:/unite_try.py", line 21, in <module>
with open(file, newline='') as f:
FileNotFoundError: [Errno 2] No such file or directory: '9788427133310_urls.csv'
The file, which is the first one in the folder, is in the right folder so I don't understand why this is happening. When I print "files" they are correct.
folder = './urls_files'
files = []
for file in os.listdir(folder):
if file.endswith('.csv'):
files.append(file)
with open('./urls_files/results.csv', 'w', newline='') as fw:
cw = csv.writer(fw, delimiter=',')
for file in files:
with open(file, newline='') as f:
for row in csv.reader(f, delimiter=','):
row.append(file)
cw.writerow(row)