botp wrote:
> On Fri, May 30, 2008 at 10:46 AM, Clement Ow
> <> wrote:
>> d= $d1
>
> where does this $d1 come from?
It is a date object in the format of MM-YY, in which this object is used
for printing datestamped folders.
>
>> src1.each do |folder|
>> Find.find(folder + "/") do |file|
>> :
>> :
>
> you cut a lot of text. pls show full source, to make our life easier..
>>>> src1 << file unless $file_exception[i].each{|x| /#{x}/ =~ File.basename(file)}
Actually how my code works is by finding all the files and then have all
the exclusions that will exclude the files in the block and then finally
executing the move, copy or delete command.
But it is just this selecting and bringing the exclusions part that is
giving me quite abit of problems. But in any case here goes my code:
def copy_r
excep_yyyymmdd = Regexp.compile($exception)
excep_ddmmyyyy = Regexp.compile($exception1)
sd_a=$source.zip($dest,$selections)
src1 = []
i = 0
sd_a.each do |sd|
$source, $destination, $selections = sd
d= $d1
dst= File.join $destination, d
if $file_exception[i] != nil
$source.each do |y|
Find.find(y + "/") do |file|
src1 << file #unless $file_exception[i].each{|x| /#{x}/ =~
File.basename(file)}
$file_exception[i].each do |ex|
src1.delete_if {|x| /#{ex}/ =~ File.basename(file)}
end
end
end
else
src1 = $source
end
i = i + 1
src1.each do |folder|
Find.find(folder + "/") do |file|
matchExp = excep_yyyymmdd.match(File.basename(file))
matchExp1 = excep_ddmmyyyy.match(File.basename(file))
if matchExp != nil or matchExp1 != nil
if $keepLastMthDay == false and $keepLastMth == false and
$createDestDir == true
begin
Dir.chdir(dest)
Dir.mkdir(d)
FileUtils.cp_r file, dst
rescue Errno::EEXIST
FileUtils.cp_r file, dst
end #rescue
puts "File Copied: #{file}\nDest: #{dst}"
elsif $keepLastMthDay == false and $keepLastMth == false and
$createDestDir == false
FileUtils.cp_r file, $destination
puts "File Copied: #{file}\nDest: #{$destination}"
elsif $keepLastMthDay == true and $keepLastMth == true
puts "Please select only one GENERAL OPTION: keepLastMth or
keepLastDayMth"
elsif ($keepLastMthDay == true or $keepLastMth == true)
puts "File Escaped: #{file} (Keep last day of month option
activated)"
end # if
elsif matchExp == nil or matchExp1 == nil
if $createDestDir == true
begin
Dir.chdir(dest)
Dir.mkdir(d)
FileUtils.cp_r file, dst #:force => true
rescue Errno::EEXIST
FileUtils.cp_r file, dst #:force => true
end #rescue
puts "File Moved: #{file}\nDest: #{dst}"
elsif $createDestDir == false
FileUtils.cp_r file, $destination #:force => true
puts "File Moved: #{file}\nDest: #{$destination}"
end # if
end # if match
if File.exist?(dst+"/"+File.basename(f)) == true or
File.exist?($destination+"/"+File.basename(f)) == true
puts "File Copy: SUCCESS"
else
#puts "File Copy: FAILED"
end #if
end #do
end #do
end #copy
--
Posted via
http://www.ruby-forum.com/.