Forum: Ruby xcopy doesn't work inside ruby?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dave C. (Guest)
on 2006-03-15 06:40
(Received via mailing list)
Hi gang,

I just tried the following in IRB:

irb(main):005:0> r = `xcopy /s a\*.* b\*.*`
Cannot perform a cyclic copy
=> "0 File(s) copied\n"
irb(main):006:0> r = `xcopy /d a\*.* b\*.*`
=> "0 File(s) copied\n"

But in a regular shell:

C:\Documents and Settings\Dev\Desktop\xcopytest>xcopy /s a\*.* b\*.*
9 File(s) copied

Both are run from the same directory, so irb shouldn't say that it can't
find folder a.

irb(main):009:0> `dir`.each { |x| puts x }
  Volume in drive C has no label.
  Volume Serial Number is C48E-4DA2

  Directory of C:\Documents and Settings\Dev\Desktop\xcopytest

03/14/2006  10:33 PM    <DIR>          .
03/14/2006  10:33 PM    <DIR>          ..
03/14/2006  10:33 PM    <DIR>          a
03/14/2006  10:33 PM    <DIR>          b
                0 File(s)              0 bytes

Any ideas?


PS What I'm looking for is a way to backup data from one drive to
another. If there's a helper library out there for this, great! If not,
I'll build the script in Ruby and hand off the copying tasks to xcopy to
do the dirty work. Much faster anyway, I'm sure.
Dave B. (Guest)
on 2006-03-15 06:55
(Received via mailing list)
Dave C. wrote:
> I just tried the following in IRB:
> irb(main):005:0> r = `xcopy /s a\*.* b\*.*`
> Cannot perform a cyclic copy
> => "0 File(s) copied\n"

You need to escape your backslashes:
irb> "xcopy /s a\*.* b\*.*"
=> "xcopy /s a*.* b*.*"
irb> "xcopy /s a\\*.* b\\*.*"
=> "xcopy /s a\*.* b\*.*"

You might also consider Ruby's FileUtils.cp(). (I haven't used it, but

Axel F. (Guest)
on 2006-03-15 10:29
(Received via mailing list)

you are on Windows? (me too...)

With FileUtils.cp, there seem to be some quirks:

If you wish to copy files, including the timestamp ("mtime"), utime
is used for this, which has a minor bug which might give you an
erroneous time with a difference of 1 hour.

If you wish to copy whole directories with FileUtils.cp_r and setting
the option :preserve=>true, in order to preserve for example the time
stamp you probably will get an error. (At least, I get it on Windows

If you copy with FileUtils from Windows XP to an USB flash drive and
then look at these files under Windows 98SE ( again ;-)  ), the
lettercase of previously all downcase filenames, which fit to the old
8.3-DOS-filename convention, will be changed to all uppercase.

I'm just tinkering with the above issues (unfortunately).

For (1) and (2), I have a "dirty" fix.

For (3), I have nothing useable.

(Of course, if you like, I can post the fixes here; but be aware,
that I'm "hobby-programmer" only, so there might be a quality-issue.)

If you are on Windows, You also might be interested in "xxcopy"; it
is someting like a very much improved version of xcopy. AFAIK, it is
free for private use.

Best regards,


I'm using ruby 1.8.4 (2005-12-24) [i386-mswin32]
This topic is locked and can not be replied to.