I have a small script I am using to relocate a tree of folders and I notice that FileUtils::mv seems to fail silently on moving some of the folders. Here is the relevant snippet:
parent = File.basename(old_parent_dir)
new_path = File.join(new_base_dir, subsection, parent)
# move to new path
begin
FileUtils::mkdir_p(new_path)
begin
FileUtils::mv(current_dir, new_path)
rescue => err
puts "unable to move #{current_dir}: #{err}"
end
rescue
puts "unable to create #{new_path}"
end
I also notice that sometimes FileUtils::mkdir_p throws an exception claiming it can't create the parent path but it does. I'm on Windows XP with Administrator privileges and the drive that the old and new trees reside on is an external firewire drive. Ruby OneClick installer (182_15)...
Not a direct answer, but take a look at rio http://rio.rubyforge.org/ ...
it's very easy to use.
rio('adir') >> rio('another_directory')
"Tim Ferrell" <Tim.Ferrell@s0nspark.com> wrote in message
news:433F3D89.2060202@s0nspark.com...
I have a small script I am using to relocate a tree of folders and I
notice that
FileUtils::mv seems to fail silently on moving some of the folders. Here
is the
relevant snippet:
parent = File.basename(old_parent_dir)
new_path = File.join(new_base_dir, subsection, parent)
# move to new path
begin
FileUtils::mkdir_p(new_path)
begin
FileUtils::mv(current_dir, new_path)
rescue => err
puts "unable to move #{current_dir}: #{err}"
end
rescue
puts "unable to create #{new_path}"
end
I also notice that sometimes FileUtils::mkdir_p throws an exception
claiming it
can't create the parent path but it does. I'm on Windows XP with
Administrator
privileges and the drive that the old and new trees reside on is an
Thanks for the tip (this looks useful) but rio suffers from the same behavior ...
I've split it up a bit and discovered that the exception is thrown when File.unlink tries to remove files in the folder after the copy. I have checked, double checked, and triple checked that I have Full Control of the tree in question (and I have no trouble doing whatever file ops I like from Explorer) but for some reason I can't delete these files with ruby.
Any other ideas? Things to check or try?
Thanks,
Tim
ps - this is under Windows XP SP 2 with an NTFS filesystem on an external firewire drive...
itsme213 wrote:
···
Not a direct answer, but take a look at rio http://rio.rubyforge.org/ ...
it's very easy to use.
rio('adir') >> rio('another_directory')
You could check to see if you don't accidentaly keep the file open.
Something like...
lines = File.open("foo", "r").readlines
will prevent you from removing foo until you exit the ruby script
since you leave it open
···
On 10/3/05, Tim <Tim.Ferrell@s0nspark.com> wrote:
I've split it up a bit and discovered that the exception is thrown when
File.unlink tries to remove files in the folder after the copy. I have
checked, double checked, and triple checked that I have Full Control of
the tree in question (and I have no trouble doing whatever file ops I
like from Explorer) but for some reason I can't delete these files with
ruby.
I can make a couple guesses (from similar issues I have previously encountered):
Something somewhere is accessing one or more of the files in the
original tree, the script itself may have a handle or current
directory set where you are trying to delete. If the problem was more
random in nature, a local indexing utility or virus scanner could also
be causing the problem.
Microsoft has a utility open handle (oh.exe) from their resource kit,
which can be downloaded from their web site (sorry I do not have the
link handy). You may want to try running it against the file/directory
when the unlink fails to see if it provides any clues.
Good luck
Patrick
···
On 10/3/05, Tim <Tim.Ferrell@s0nspark.com> wrote:
I've split it up a bit and discovered that the exception is thrown when
File.unlink tries to remove files in the folder after the copy.
It will show you all open handles for any process, and even let you
close any of the handles. (Not always the best thing to do, depending
on what the process is doing with the handle.)
Process Explorer has lots of other useful features. When doing
development on Windows, I find it an invaluable tool.
Wayne Vucenic
No Bugs Software
Ruby and C++ Agile Contract Programming in Silicon Valley
···
On 10/3/05, Patrick Hurley <phurley@gmail.com> wrote:
Microsoft has a utility open handle (oh.exe) from their resource kit,
which can be downloaded from their web site (sorry I do not have the
link handy).