Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > If error occurs should not copy again from the beginning

Reply
Thread Tools

If error occurs should not copy again from the beginning

 
 
Newb Newb
Guest
Posts: n/a
 
      04-29-2009
Hi..
I try to copy folders recursively..

my_dir = Dir.glob( Dir.glob("#{@source}/**/*")

my_dir.each do |f|
File.copy(f,@@dest)
end

For example @source = e:/test_dir
If that test_dir has 10 files.if some error occurs while copying a 4th
file,Again copying of the file should not continue from 1st file to 10th
file again.
If that 4 th file not copied due to any errors it should continue
copying from 5 th file and so on...

I think using arrray index might do the trick.
Any ideas
Thanks
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Heesob Park
Guest
Posts: n/a
 
      04-29-2009
Hi,

2009/4/29 Newb Newb <>:
> Hi..
> I try to copy folders recursively..
>
> =C2=A0my_dir =3D Dir.glob( Dir.glob("#{@source}/**/*")
>
> =C2=A0my_dir.each do |f|
> =C2=A0 File.copy(f,@@dest)
> =C2=A0end
>
> For example @source =3D e:/test_dir
> If that test_dir has 10 files.if some error occurs while copying a 4th
> file,Again copying of the file should not continue from 1st file to 10th
> file again.
> =C2=A0 =C2=A0 If that 4 th file not copied due to any errors it should co=

ntinue
> copying from 5 th file and so on...
>
> I think using arrray index might do the trick.
> Any ideas
> Thanks


my_dir.each do |f|
begin
FileUtils.copy(f,@@dest)
rescue
# some error handling
end
end

Or

my_dir.each do |f|
FileUtils.copy(f,@@dest) rescue nil
end


Regards,

Park Heesob

 
Reply With Quote
 
 
 
 
7stud --
Guest
Posts: n/a
 
      04-29-2009
Newb Newb wrote:
> Hi..
> I try to copy folders recursively..
>
> my_dir = Dir.glob( Dir.glob("#{@source}/**/*")
>
> my_dir.each do |f|
> File.copy(f,@@dest)
> end
>
> For example @source = e:/test_dir
> If that test_dir has 10 files.if some error occurs while copying a 4th
> file,Again copying of the file should not continue from 1st file to 10th
> file again.
> If that 4 th file not copied due to any errors it should continue
> copying from 5 th file and so on...
>
> I think using arrray index might do the trick.
> Any ideas
> Thanks


10.times do |i|
begin
puts "reading file #{i}"

if i == 4
raise "error reading file #{i}"
end

rescue RuntimeError => msg
puts msg
next
end
end

--output:--
reading file 0
reading file 1
reading file 2
reading file 3
reading file 4
error reading file 4
reading file 5
reading file 6
reading file 7
reading file 8
reading file 9

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
7stud --
Guest
Posts: n/a
 
      04-29-2009
7stud -- wrote:


rescue RuntimeError => msg
puts msg
next <---***Don't need that
end
end



--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
index of string from beginning of line vs beginning of file Jesse B. Ruby 9 03-27-2010 04:04 PM
'For loop not initialized' error occurs on one machine and not another... Chad ASP General 4 02-28-2005 06:31 PM
Re: Should I always call PyErr_Clear() when an exception occurs? Tim Peters Python 0 12-21-2004 06:17 AM
Should I always call PyErr_Clear() when an exception occurs? Jaime Wyant Python 0 12-21-2004 05:28 AM
Display error message if an error occurs on "open" command Geek Perl Misc 3 12-02-2003 11:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57