Bug #12585
Updated by tobymurray-nanometrics (Toby Murray) over 8 years ago
In Windows 10, running as administrator:
~~~
λ C:\tools\ruby\23-x64\bin\irb.cmd
irb(main):001:0> require 'fileutils'
=> true
irb(main):002:0> FileUtils.mkdir("first_directory")
=> ["first_directory"]
irb(main):003:0> FileUtils.mkdir("second_directory")
=> ["second_directory"]
irb(main):004:0> FileUtils.touch(File.join("first_directory", "test_file"))
=> ["first_directory/test_file"]
irb(main):005:0> file = File.new(File.join("first_directory", "test_file"))
=> #<File:first_directory/test_file>
irb(main):006:0> FileUtils.move(file, "second_directory")
Errno::EACCES: Permission denied @ rb_file_s_rename - (first_directory/test_file, second_directory/test_file)
from C:/tools/ruby/23-x64/lib/ruby/2.3.0/fileutils.rb:528:in `rename'
from C:/tools/ruby/23-x64/lib/ruby/2.3.0/fileutils.rb:528:in `block in mv'
from C:/tools/ruby/23-x64/lib/ruby/2.3.0/fileutils.rb:1571:in `block in fu_each_src_dest'
from C:/tools/ruby/23-x64/lib/ruby/2.3.0/fileutils.rb:1585:in `fu_each_src_dest0'
from C:/tools/ruby/23-x64/lib/ruby/2.3.0/fileutils.rb:1569:in `fu_each_src_dest'
from C:/tools/ruby/23-x64/lib/ruby/2.3.0/fileutils.rb:517:in `mv'
from (irb):6
from C:/tools/ruby/23-x64/bin/irb.cmd:19:in `<main>'
~~~
I've tried various invocations of `FileUtils.move`, passing file/directory objects or strings, and everything seems to end up the same. Am I using this incorrectly?
----
It appears I was using this incorrectly. `File.new` actually opens the file, which prevents it from being moved. If that's as intended, I guess this is not a bug.