# Quicken copy time when processing large files

**URL:** <https://www.ruby-forum.com/t/quicken-copy-time-when-processing-large-files/133850>\
**Category:** Ruby\
**Created:** [April 4, 2008, 12:16pm UTC](https://www.ruby-forum.com/t/quicken-copy-time-when-processing-large-files/133850 "2008-04-04T12:16:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![owc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/74df32/32.png) [@owc](https://www.ruby-forum.com/u/owc)\
**Post date:** [April 4, 2008, 12:16pm UTC](https://www.ruby-forum.com/t/quicken-copy-time-when-processing-large-files/133850/1 "2008-04-04T12:16:51Z")

</div>

I just started ruby not too long ago and I’m really new to the language.  
But I came out with something; to copy files from path names to path  
names using each respecive array elements.

* * *

$options=  
[“2008\*”, “2008\*”, “700\*”, “2008\*”, “2008\*”]

$source=  
%w[C:/movtest/testing  
C:/movtest/testing/new  
U:/movtest/source  
U:/movtest/new  
U:/movtest/new1]

$dest=  
%w[U:/test\_1/ U:/dest1/ U:/dest2/ U:/dest3/ U:/dest4/]

while i\<=j && i1\<=j1 && i2\<=j2

Dir.chdir($source[i])  
print "\nSource: " + Dir.getwd + “\t\n”  
print “Dest: " + $dest[i1] + “\n”  
print “Options: " + $options[i2] +”\n”  
FileUtils.cp\_r Dir.glob($options[i2]), $dest[i1]  
print “File Mov Test:Success”  
i+=1  
i1+=1  
i2+=1  
end

* * *

Apparently, when moving large files (i.e file size 50mb) it takes  
relatively long as when i use ROBOCOPY (a robust copying software by  
MSServer), but I cant use robocopy because it has it’s limitations,hence  
i used ruby. As I will be running the ruby program on a server, I cant  
afford to use too much memory while transferring files from one folder  
to another as the server is used for more impt tasks like running impt  
applications in the office.

So is there anything that i could do to quicken the copying process  
without compromising on the ability to have different path names and  
options for copying files? (i understand that arrays do take up more  
memory)  
Thanks in advance. =)

---

<div class="post-metadata">

**Author:** ![owc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/74df32/32.png) [@owc](https://www.ruby-forum.com/u/owc)\
**Post date:** [April 8, 2008, 8:53am UTC](https://www.ruby-forum.com/t/quicken-copy-time-when-processing-large-files/133850/2 "2008-04-08T08:53:18Z")

</div>

Clement Ow wrote:

> I just started ruby not too long ago and I’m really new to the language.  
> But I came out with something; to copy files from path names to path  
> names using each respecive array elements.

You might try something such as:

#!/usr/bin/ruby

def copyfiles(files)  
files = files.split(",")

print "Copy to Where?: "  
dir = gets.strip!  
curdir = Dir.pwd

files.each do |copy|  
Dir.chdir(curdir)  
input = []  
IO.foreach(copy){|x| input \<\< x}

Dir.chdir("/")  
Dir.chdir(dir)  
output = File.new(copy,‘w+’)  
output.puts input  
output.close()  
end  
end

copyfiles(‘testdoc1.txt,testdoc2.txt’)

#######

I’m not familiar with ROBOCOPY so I dont know what the memory usage  
difference would be between this and robocopy, but give it a shot and  
see what happens.

- Mac
