# Xcopy doesn't work inside ruby?

**URL:** <https://www.ruby-forum.com/t/xcopy-doesnt-work-inside-ruby/82093>\
**Category:** Ruby\
**Created:** [March 15, 2006, 5:40am UTC](https://www.ruby-forum.com/t/xcopy-doesnt-work-inside-ruby/82093 "2006-03-15T05:40:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [March 15, 2006, 5:40am UTC](https://www.ruby-forum.com/t/xcopy-doesnt-work-inside-ruby/82093/1 "2006-03-15T05:40:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [March 15, 2006, 5:55am UTC](https://www.ruby-forum.com/t/xcopy-doesnt-work-inside-ruby/82093/2 "2006-03-15T05:55:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [March 15, 2006, 9:29am UTC](https://www.ruby-forum.com/t/xcopy-doesnt-work-inside-ruby/82093/3 "2006-03-15T09:29:45Z")

</div>

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 😉 ), 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]
