title: ruby - Permission denied after File.open and rename
body: <p>I modify a file and then try to rename it and rename his directory.
  But I get a permission denied error.</p>
  
  <p>Here is my code :</p>
  
  <pre><code># 1) Modify the xml file
  
  Xml_file = "Directory/foo.xml"
  
  begin
      contents = File.new(Xml_file).read
      $document = REXML::Document.new(contents)
      $document.root.elements["label"].text = "some text"  
  
      File.open(Xml_file, "w") do |data|
      data&lt;&lt;$document
  end
  
  ensure
      $document = nil
  end
  
  # 2) Then rename the file and the directory
  
  old_name = Xml_file
  new_name = "Directory/new_name.xml"
  File.rename(old_name, new_name) # OK, this works !
  
  old_dir = "Directory"
  new_dir = "New_Directory"
  FileUtils.mv(old_dir, new_dir) # Crash, saying "permission denied"
  </code></pre>