title: Ruby moving directory error:
body: <p>I have a directory with many subdirectories and each of the subdirectories contains a different version of programme to test.</p>
  
  <pre><code>all_dirs.each do |dir|
    FileUtils.mv(test_spec, target_dir, :verbose =&gt; true)
    system("rspec #{test_folder_name}")
    puts "moving back: '#{spec_dir}' to '#{current_dir}'"
    FileUtils.mv(spec_dir, current_dir, :verbose =&gt; true)
  end
  </code></pre>
  
  <p>In most cases the code is successful, however sometimes it refuses to move a directory to a parent directory, because it already exists.</p>
  
  <pre><code>mv ~/test/version-1/01-spec ~/test
  ~/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:509:in `block in mv': File exists - ~/test (Errno::EEXIST)
          from ~/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:1423:in `block in fu_each_src_dest'
          from ~/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:1437:in `fu_each_src_dest0'
          from ~/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:1421:in `fu_each_src_dest'
          from ~/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:504:in `mv'
  </code></pre>
  
  <p>The unix <code>mv</code> command is valid and can be executed after this exception was thrown. Am I doing something wrong?</p>