I'm trying to generate a .csv file that lists all .txt file in a sub-directory but can exclude a .txt file of a certain size.
Without an if statement around file size, I can successfully generate the .csv file list that has the full paths to the .txt files (1105 files total)
import os
import csv
import os.path
mtn_path = "TEXT_FILE_PATH\\"
a = open(mtn_path + "output.csv", 'w+', newline='')
num_files = 0
for path, dirnames, filenames in os.walk(mtn_path):
for filename in [f for f in filenames if f.endswith(".txt")]:
# if os.stat(filename).st_size > 20000:
f = os.path.join(path, filename)
a.write(str(f) + os.linesep)
num_files = num_files + 1
)
#
print("The total number of text files found was " + str(num_files))
When I include the if os.stat line, I get the error:
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'INT_NR_H1000Cu_000.mtn_001.txt'
That particular .txt file is the first one listed in the csv file of the working code.