Oct-25-2018, 12:36 PM
I have program, which looks for every files starting with mli_value_IHAR_. I want these files' special date ID into a file (every date into a new line). Here is the code that I wrote. My problem is that the final txt file contains only the last element's date. Where do I make a mistake?
for path, subdirs, files in os.walk(r'./'): for filename in files: if filename.startswith("mli_value_IHAR_"): f = os.path.join(path, filename) print(f) date = (f[-12:-4]) print(date) with open('test.txt', 'w') as data_file: data_file.write(str('%s\n' % date))