title: Stuck in a recursive directory search using os.scandir
body: <p>I'm searching through a large directory to sort an old archive into a specific order. I have embedded a function which is called recursively and when it finds a directory whose file path matches the search criteria it adds it to the 'found' dictionary <code>fdict</code>.</p>
  
  <p>The expected outcome is that when the function is called on a directory with no subdirectories it completes with no actions and moves back up a level.</p>
  
  <p>When run it gets stuck in the first directory it finds that contains no sub-directories and simply recursively calls the current directory for a search, getting stuck in a loop.</p>
  
  <p>Below is the code abstract, any insight into why it is looping would be much appreciated.</p>
  
  <pre><code>def scan(queries, directory):
      fdict = {}
      def search(queries, directory, fdict):
          for entry in os.scandir(directory):
              if entry.is_dir():
                  for x in queries:
                      if str(x) in entry.path:
                          fdict[str(x)] = entry.path
                          print("{} found and dicted".format(str(x)))
                      else:
                          search(queries, entry.path, fdict)
              else: pass
      search(queries, directory, fdict)
      return fdict
  </code></pre>