清空文件夹下所有文件的内容
import os
class BatchRename():
def __init__(self):
self.path = '/home/jojo/VSST/zqz/Batch_processing_of_documents/Empty_the_contents_of_all_files_in_the_folder/labels'
def close(self):
filelist = os.listdir(self.path)
filelist.sort()
total_num = len(filelist)
for item in filelist:
if item.endswith('.txt'):
src = os.path.join(os.path.abspath(self.path), item)
src = open(src,'w')
src.truncate(0)
print ('total %d to close' % (total_num))
if __name__ == '__main__':
demo = BatchRename()
demo.close()