title: OSError: Directory not empty raised, how to fix?
body: <p>I'm just trying to write a little application that takes a value from a file named 'DATA.DAT' and renames the folder which contains that file with that value.</p>
  
  <p>The .py script runs in another folder and allows the user to define the path. To give you a better idea, the user defined path must be like (on a mac) '/Users/User/Desktop/FOLDER' and 'FOLDER' should contain 'DATA.DAT'.</p>
  
  <p>That's how a little part of the source code looks like:</p>
  
  <pre><code>try:
      data = open('DATA.DAT').read()
  
      data_data = data[12:17]
      path_paths = path.rsplit('/')
      basepath = '/'.join(path_paths[:-1])
      chdir(basepath)
  
      if path_paths[-1] &lt;&gt; data_data:
          rename(path_paths[-1], data_data)
          raw_input('Folder name has been corrected! Thank you.')
          quit()
      else:
          print('Folder name was already correct! Thank you.')
          quit()
  except IndexError:
      raw_input('ERROR!')
      quit()
  </code></pre>
  
  <p>Well, it works; but it raise and exception when 'FOLDER' contains more than one file (actually, 'FOLDER' should contain just 'DATA.DAT' and other folders. That doesn't give problems.)...</p>
  
  <pre><code>Traceback (most recent call last):
    File "/Users/User/Desktop/example.py", line 72, in &lt;module&gt;
      rename(path_paths[-1], data_data)
  OSError: [Errno 66] Directory not empty
  </code></pre>
  
  <p>Just to prevent that this happens, is there a way to fix it? Thanks.</p>