title: FileNotFoundError while iterating over folders/files in a given directory
body: <p>The objective of my program is to retrieve all folders' sizes in a given path/directory. The following function is something that I used to calculate a specific folder's size.</p>
  <pre><code>def get_folder_sz(self, folder_path: str):
      if os.path.isfile(folder_path):
          print('Only folder size can be calculated with the &quot;get_folder_sz&quot; function!&quot;')
          sys.exit(0)
  
      folder_size = os.stat(folder_path).st_size
  
      try:
          for item in os.listdir(folder_path):
              item_path = os.path.join(folder_path, item)
  
              if os.path.isfile(item_path):
                  folder_size += os.path.getsize(item_path)
              elif os.path.isdir(item_path):
                  folder_size += self.get_folder_sz(item_path)
      except PermissionError as error:
          pass
  
      return folder_size
  </code></pre>
  <p>However, for one reason or another, the program raises the <code>FileNotFoundError</code> when calling the function above and I can't seem to find any logical errors in the function that would cause this.</p>
  <p>The function only iterates itself if <code>item</code> is proven to be a directory, so I'm not sure why the file outputted by <code>os.listdir</code> would not be found.</p>
  <p>Error Message:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;main.py&quot;, line 53, in &lt;module&gt;
      analyzer.iterate_dir('C:\\', 1)
    File &quot;main.py&quot;, line 24, in iterate_dir
      if os.path.isdir(item_path) and self.get_folder_sz(item_path) == 0:
    File &quot;main.py&quot;, line 45, in get_folder_sz
      folder_size += self.get_folder_sz(item_path)
    File &quot;main.py&quot;, line 45, in get_folder_sz
      folder_size += self.get_folder_sz(item_path)
    File &quot;main.py&quot;, line 45, in get_folder_sz
      folder_size += self.get_folder_sz(item_path)
    [Previous line repeated 19 more times]
    File &quot;main.py&quot;, line 39, in get_folder_sz
      for item in os.listdir(folder_path):
  FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\Lenovo\\.gradle\\caches\\transforms-2\\files-2.1\\8da17c8c9c06e565b531c4225313a5eb\\unzipped-distribution\\gradle-6.3\\subprojects\\build-init\\src\\integTest\\resources\\org\\gradle\\buildinit\\plugins\\MavenConversionIntegrationTest\\expandProperties\\src\\main\\java'
  </code></pre>
  <p>I'd appreciate any help possible!</p>