I have 500 text files in a folder. How do I find out how many lines each text file have, and delete them if it has more than 300 lines.
import os
path = "All_TSV_Files"
files = [file for file in os.listdir(path) if file.endswith(".txt")]
for file in files:
with open(os.path.join(path, file), 'r',encoding='utf-8') as f:
#find the lines of each file