title: "A subdirectory of file txt already exists." error when trying to sort files, even though there are no files name "txt"
body: <p>I'm trying to make a python script that moves all files with a specific extension into respective folders, which are named with the extension, like TXT. However, upon running the code it comes up with the error &quot;A subdirectory of file txt already exists.&quot; but after looking in the folder that has the files that need to be sorted, there hasn't even been a file created with such name.</p>
  <pre class="lang-py prettyprint-override"><code>import os
  import shutil
  
  try:
      path = &quot;/Users/name/Desktop/test2/&quot;
      for (path, dirs, files) in os.walk(path):
          for file in files:
              extension=file.split('.')[1]
              print(extension)
              if os.path.exists(r&quot;/Users/name/Desktop/test2/&quot; +extension):
                  if file.endswith(extension):
                      shutil.move(file, &quot;/Users/name/Desktop/test2/&quot; +extension)
              else:
                  os.system('mkdir ' + extension)
                  shutil.move(file, &quot;/Users/name/Desktop/test2/&quot; +extension)
  except:
      print(&quot;done&quot;)
  </code></pre>