I have thousands of files inside a directory with this pattern YYYY/MM/DD/HH/MM:
- 201801010000.txt
- 201801010001.txt
- 201801010002.txt
I want to keep just the hours, so I need to merge 60 files into one for every hour of every day. I don't know how to search into the filename to get the 60 files that i want. This is what I wrote
def concat_files(path):
file_list = os.listdir(path)
with open(datetime.datetime.now(), "w") as outfile:
for filename in sorted(file_list):
with open(filename, "r") as infile:
outfile.write(infile.read())
How do I name the file to keep the date? I'm using datetime now but it override the current filename. With my code I'm merging all files into one, I should merge every % 60 into a different file.