citizenSNIPS citizenSNIPS - 1 year ago 103
Python Question

measure progress (time left) while os.listdir is generating a list (Python)

In Python 2.7, I am using

to generate a list of files in a folder. There are lots of files and my connection to the folder is slow so it can take up to 30 seconds to complete. Here is an example:

import os
import time

start_time = time.time()
dir_path = r'C:\Users\my_name\Documents\data_directory' #example path
file_list = os.listdir(dir_path)

print 'it took', time.time() - start_time, 'seconds'

This is for a Tkinter GUI I'm working on and I would like make a status bar showing how much time or percentage is left for this step that takes a long time (about 30 seconds).

Is there a way to show the time left or percentage left to complete the
file_list = os.listdir(dir_path)

Answer Source

You ought to use scandir which is only available with Python 3.

But there is a back port.

To understand the problem, read PEP 471.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download