title: Delete a directory that is not empty on python
body: <p>So, I need to clean a directory that is not empty.
  I have created the following function.For testing reasons I tried to remove a JDK installation</p>
  
  <pre><code>def clean_dir(location):
      fileList = os.listdir(location)
  
      for fileName in fileList:
          fullpath=os.path.join(location, fileName)
          if os.path.isfile(fullpath):
              os.chmod(fullpath, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
              os.remove(location + "/" + fileName)
          elif os.path.isdir(fullpath):
              if len(os.listdir(fullpath)) &gt; 0:
                  clean_dir(fullpath)
              #os.rmdir(location + "/" + fileName)
              shutil.rmtree(location + "/" + fileName)
  
      return
  </code></pre>
  
  <p>I tried to use rmtree and rmdir, but it fails.</p>
  
  <p>The error I got using rmtree is:</p>
  
  <blockquote>
    <p>OSError: Cannot call rmtree on a symbolic link</p>
  </blockquote>
  
  <p>And this is the error I got when I used rmdir:</p>
  
  <blockquote>
    <p>OSError: [Errno 66] Directory not empty:
    '/tmp/jdk1.8.0_25/jre/lib/amd64/server'</p>
  </blockquote>
  
  <p>The code works correctly on windows. But for some reason it fails on linux.</p>