darren kirby wrote: > Hello all, > > A script I have written needs the ability to move files. I thought I would > be clever and use File.rename(old, newdir + new) but this is giving me an > error: `rename': Invalid cross-device link. I gather this is because I am > renaming the file to a different partition. No, it is because you are trying to use "rename" to physically move a file, and the system is objecting to this misconception. File.rename can only rename files, it cannot move them. It works only on one storage device/volume/whatever. > So then I found FileUtils and used: > require 'fileutils' > include FileUtils > mv( old, new) > > This is working but seems an overly verbose and convoluted way to move a > file. Umm, compared to what? It moves the file using a method named "mv", just like the Linux/Unix command of the same name. > I had a look at the fileutils.rb source and found this (for 'mv'): > # Moves file(s) +src+ to +dest+. If +file+ and +dest+ exist on the > # different disk partition, the file is copied instead That is what "mv" does. If the new and old filenames and paths allow the file to remain on the same device, a simple rename is carried out. If not, the file is copied to the destination and deleted from the source. > So I guess my real question is: is there a technical reason or some > arbitrary reason there is no File.move() method that can handle this > transparently? I would think it would be quite useful... It might be because not all operating systems on which Ruby can be installed know the "mv" operation as described above. Just a guess. -- Paul Lutus http://www.arachnoid.com