# Exceptions in file copying

**URL:** <https://www.ruby-forum.com/t/exceptions-in-file-copying/134256>\
**Category:** Ruby\
**Created:** [April 9, 2008, 10:03am UTC](https://www.ruby-forum.com/t/exceptions-in-file-copying/134256 "2008-04-09T10:03:29Z")\
**Posts on this page:** 3\
**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 9, 2008, 10:03am UTC](https://www.ruby-forum.com/t/exceptions-in-file-copying/134256/1 "2008-04-09T10:03:29Z")

</div>

All,  
First of all,  
Thanks to those who helped out in my previous thread. It was really of  
great help. 🙂 Alright now, another issue i just can figure out, so i  
decided to post a new thread 😉

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/]

selections=[“2008\*”, “2008\*”, “2008\*”, “asd\*”, “asd\*”]

# here i combine those 3 arrays into 1 multi-dim array

sd\_a=source.zip(dest,selections)  
#puts sd\_a

sd\_a.each do |sd|  
source, destination, selections = sd  
src = File.join source,selections  
puts “Source: #{src}”  
puts “Dest: #{destination}”

FileUtils.cp\_r Dir.glob(src), destination

puts “File Copy Test:Success”  
end

I have a folder in C:\movtest\testing\ and i want to leave the last day  
of the mth untouched(which means i dont wanna copy them over to the dest  
path.) For example, I wanna copy any file or folder starting with 2008  
but I want to keep 20080331 which is the last day of the previous mth  
untouched. Is there any way i can put an exception to the command,  
‘FileUtils.cp\_r Dir.glob(src), destination’ ?

---

<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 9, 2008, 10:32am UTC](https://www.ruby-forum.com/t/exceptions-in-file-copying/134256/2 "2008-04-09T10:32:01Z")

</div>

From: Clement Ow [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

# I have a folder in C:\movtest\testing\ and i want to leave

# the last day

# of the mth untouched(which means i dont wanna copy them over

# to the dest

# path.) For example, I wanna copy any file or folder starting with 2008

# but I want to keep 20080331 which is the last day of the previous mth

# untouched. Is there any way i can put an exception to the command,

# ‘FileUtils.cp\_r Dir.glob(src), destination’ ?

Dir.glob returns an array

irb(main):012:0\> Dir.glob(“2008\*”)  
=\> [“20080331”, “2008abc”, “2008def”, “2008ghi”]

and you can (easily) subtract arrays by the “-” operator

irb(main):014:0\> [1,2,3] - [3]  
=\> [1, 2]

so you can do something like

irb(main):015:0\> Dir.glob(“2008\*”) - [“20080331”]  
=\> [“2008abc”, “2008def”, “2008ghi”]

kind regards -botp

---

<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 10, 2008, 5:25am UTC](https://www.ruby-forum.com/t/exceptions-in-file-copying/134256/3 "2008-04-10T05:25:32Z")

</div>

> Dir.glob returns an array
> 
> irb(main):012:0\> Dir.glob(“2008\*”)  
> =\> [“20080331”, “2008abc”, “2008def”, “2008ghi”]
> 
> and you can (easily) subtract arrays by the “-” operator
> 
> irb(main):014:0\> [1,2,3] - [3]  
> =\> [1, 2]
> 
> so you can do something like
> 
> irb(main):015:0\> Dir.glob(“2008\*”) - [“20080331”]  
> =\> [“2008abc”, “2008def”, “2008ghi”]

Exactly what i wanted! 🙂  
Thanks and regards,  
Clement
