Xcopy doesn't work inside ruby?


#1

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*.*
a\1.file
a\2.file
a\3.file
a\4.file
a\5.file
a\files\1.file
a\files\2.file
a\files\3.file
a\files\4.file
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 .
03/14/2006 10:33 PM …
03/14/2006 10:33 PM a
03/14/2006 10:33 PM b
0 File(s) 0 bytes

Any ideas?

Thanks,
-dave

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.


#2

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
it’s
there.)

Cheers,
Dave


#3

Hello,

you are on Windows? (me too…)

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

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

(2)
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
98SE.)

(3)
If you copy with FileUtils from Windows XP to an USB flash drive and
then look at these files under Windows 98SE (…me again :wink: ), 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,

Axel

I’m using ruby 1.8.4 (2005-12-24) [i386-mswin32]