From: "Allton, Paul" Date: 2003-11-27T02:56:58+09:00 Subject: Re: Stupid Question #498 - How do I move a directory? > -----Original Message----- > From: Berger, Daniel [mailto:djberge@qwest.com] > That means there was something wrong with your choice of file names > because File.move in ftools.rb attempts to call 'rename' first. Only if > that fails does it resort to readlink. My guess would be that either > 'old' does not exist, or that you forgot to include a double backslash > inside double quotes, e.g. "C:\temp1" vs "C:\\temp1". FileTest.exist?(old) #> true I'm using forward slashes, instead of escaped backslashes as that seems to work well for the rest of the file stuff. (I've tried it with double backslashes anyway, but it made no difference). > You can avoid ftools or fileutils altogether and simply use File.rename. > Just tested it on my Windows XP box and it works fine. I actually tried File.rename(old, newdir) and it kind of worked if I did it on its own. However, when I tried this: File.open(file).readlines.each do | line | #do stuff end File.rename(old, newdir) I got permission denied. 'file', is located in 'old' so if it wasn't closed then that would make sense. I initially read that File.open automatically closed itself at the end, but re-reading I now see that's only if you give it a block. Doh! ... so finally, this worked: f = File.open(file) f.readlines.each do | line | #do stuff end f.close File.rename(olddir, newdir) -------------------------------------------------------------------------------- The information contained herein is confidential and is intended solely for the addressee. Access by any other party is unauthorised without the express written permission of the sender. If you are not the intended recipient, please contact the sender either via the company switchboard on +44 (0)20 7623 8000, or via e-mail return. If you have received this e-mail in error or wish to read our e-mail disclaimer statement and monitoring policy, please refer to http://www.drkw.com/disc/email/ or contact the sender. --------------------------------------------------------------------------------