import os, glob strings = ("abcdefghijklmnopqrstuvwxyz") for file in glob.glob(r"C:\temp\python\*.txt"): lines = open(file).readlines() with open(file) as myFile: for num, line in enumerate(myFile, 1): if any(s in line for s in strings): val = num try: open(r'C:\temp\python\newfile.txt', 'w').writelines(lines[val:]) os.remove(file) os.rename(r'C:\temp\python\newfile.txt', file) except IndexError: pass
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.