FileUtils and Windows XP

T

Tim Ferrell

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)...

Any ideas? I'm about to pull my hair out! :-(

Thanks,
Tim
 
T

Tim

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...
 
C

Cristi BALAN

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?

You could check to see if you don't accidentaly keep the file open.
Something like...

lines =3D File.open("foo", "r").readlines

will prevent you from removing foo until you exit the ruby script
since you leave it open
 
P

Patrick Hurley

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.

Any other ideas? Things to check or try?

I can make a couple guesses (from similar issues I have previously encounte=
red):

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
 
W

Wayne Vucenic

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).

The SysInternals website has a great free utility called Process Explorer:

http://www.sysinternals.com/Utilities/ProcessExplorer.html

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top