with open('C:/Users/JDoe/Downloads/rows_to_del.txt', 'r', encoding="utf8") as f:
delete_docs = [line.rstrip('\n') for line in f]
print(delete_docs)
def txtUpdater():
path = "C:/Users/JDoe/Downloads/TEST2/*.txt"
files = glob.glob(path)
for name in files:
with open(name, 'r', encoding="utf8") as originaltxt, open("C:/Users/JDoe/Downloads/Output/Output.txt", 'w', encoding="utf8") as updatedtxt:
for line in originaltxt:
if not any(delete_doc in line for delete_doc in delete_docs):
updatedDAT.write(line)
在上面的“路径”中,TEST2
文件夹具有多个子文件夹。在每个文件中都有文本文件。如何让Python访问TEST2内多个子文件夹内的所有文本文件,并按照上面的代码做我想做的事情?
我尝试在路径中的TEST2(“ / *”)后面放置通配符,但是代码没有任何作用。
path = "C:/Users/JDoe/Downloads/TEST2/*/*.txt"