我的目录中至少有3700个文本文件(实际上是标签),以及相同数量的jpg / jpeg图像。 在所有这些文本文件中,数百个文本为:
1 0.19140625 0.50078125 0.3078125 0.9484375
我想删除其中存在的每个文本文件中从1开始的行。 我尝试了以下操作:
import os
import glob
import errno
path = '~/Documents/txt/*.txt'
path1 = '~/Documents/txt/'
files = glob.glob(path)
txtfile = []
temp_path = os.path.join(path1,'temp.txt')
for name in files:
try:
with open(name,'r') as f,open(temp_path) as temp:
for line in f:
if line.strip() == "1":
continue
temp.write(line)
except IOError as exc:
if exc.errno != errno.EISDIR:
raise
#print(txtfile)