如何使用python中的搜索文件绑定TQM progressbar

如何使用python中的搜索文件绑定TQM progressbar,python,tqdm,Python,Tqdm,我写了一个函数,用tqdm progressbar搜索文件。但如何编写代码以避免在列出文件(图像)时出现这种效果: 我只需要一个progressbar,它可以同时加载列表文件 counter = 0 filepath = "." ext = ".txt" # for example for fil in os.listdir(filepath):

我写了一个函数,用tqdm progressbar搜索文件。但如何编写代码以避免在列出文件(图像)时出现这种效果: 我只需要一个progressbar,它可以同时加载列表文件

        counter = 0
            filepath = "." 
            ext = ".txt" # for example
            for fil in os.listdir(filepath):
                if fil.endswith(ext):
                    print(fil)
                    counter+=1
                    sleep(0.01)
                for i in tqdm(range(counter)):
                    i+=1
            print("\nNumber of found elements: "+str(counter))

迭代时使用TQM:

        filepath = "." 
        ext = ".txt" # for example
        for fil in tqdm(os.listdir(filepath)):
            if fil.endswith(ext):
                print(fil)
                counter+=1
                sleep(0.01)
        print("\nNumber of found elements: "+str(counter))