measure progress (time left) while os.listdir is generating a list (Python)
<p>In Python 2.7, I am using <code>os.listdir</code> 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:</p>

<pre><code>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'
</code></pre>

<p>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).</p>

<p>Is there a way to show the time left or percentage left to complete the <code>file_list = os.listdir(dir_path)</code> step???</p>

<p>You ought to use <code>scandir</code> which is only available with Python 3. </p>

<p>But there is a <a href="https://pypi.python.org/pypi/scandir" rel="nofollow">back port.</a> </p>

<p>To understand the problem, read <a href="https://www.python.org/dev/peps/pep-0471/" rel="nofollow">PEP 471</a>. </p>

python tkinter operating-system listdir