Exceptions in file copying

C

Clement Ow

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' ?
 
C

Clement Ow

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top