title: How to get progress bar with tqdm in a for loop over directory
body: <p>I am trying to conditionally load some files from a directory. I would like to have a progress bar from tqdm on the process. I currently running this:</p>
  
  <pre><code>loaddir = r'D:\Folder'
  # loop the files in the directory
  print('Data load initiated')
  for subdir, dirs, files in os.walk(loaddir_res):
      for name in tqdm(files):
          if name.startswith('Test'):
              #do things
  </code></pre>
  
  <p>which gives</p>
  
  <pre><code>Data load initiated
  
    0%|          | 0/6723 [00:00&lt;?, ?it/s]
    0%|          | 26/6723 [00:00&lt;00:28, 238.51it/s]
    1%|          | 47/6723 [00:00&lt;00:31, 213.62it/s]
    1%|          | 72/6723 [00:00&lt;00:30, 220.84it/s]
    1%|▏         | 91/6723 [00:00&lt;00:31, 213.59it/s]
    2%|▏         | 115/6723 [00:00&lt;00:30, 213.73it/s]
  </code></pre>
  
  <p>This has two problems:</p>
  
  <ol>
  <li>When progress is updated a new line appears in my IPython console in Spyder</li>
  <li>I am actually timing the loop over the files and not over the files that start with 'Test' and therefore progress and remaining time are not accurate.</li>
  </ol>
  
  <p>However, if I try this:</p>
  
  <pre><code>loaddir = r'D:\Folder'
  # loop the files in the directory
  print('Data load initiated')
  for subdir, dirs, files in os.walk(loaddir_res):
      for name in files:
          if tqdm(name.startswith('Test')):
              #do things
  </code></pre>
  
  <p>I get the following error.</p>
  
  <pre><code>Traceback (most recent call last):
  
    File "&lt;ipython-input-80-b801165d4cdb&gt;", line 21, in &lt;module&gt;
      if tqdm(name.startswith('Probe')):
  
  TypeError: 'NoneType' object cannot be interpreted as an integer
  </code></pre>
  
  <p>I would like to have a progress bar in only one line that updates whenever the <code>startswith</code> loop is activated.</p>
  
  <p><strong>----UPDATE----</strong></p>
  
  <p>I also found out <a href="https://github.com/tqdm/tqdm/issues/78" rel="nofollow noreferrer">here</a> that it can also be used like this:</p>
  
  <pre><code>files = [f for f in tqdm(files) if f.startswith('Test')]
  </code></pre>
  
  <p>Which allows to track progress with list comprehension by wrapping the iterable with tqdm. However in spyder this results in a separate line for each progress update.</p>
  
  <p><strong>----UPDATE2----</strong>
  It actually works fine in spyder. Sometimes if the loop fails, it might go back to printing one line of progress update. But i haven't seen this very often after the latest updates.</p>