[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Two rescues?

STEPHEN BECKER I V

10/9/2004 1:21:00 AM

begin
recurse(File::join(path, dir), max_depth - 1) if max_depth > 0
rescue Errno::EACCES => e # do not have access to folder skip it
rescue Errno::DontRemember =>
end

Can i do this? if not is there a way to jimmy-rig around this? I have
a program that i want to run on windows and linux but i get differnt
file errors from the two systems.
Becker


4 Answers

Florian Frank

10/9/2004 8:50:00 AM

0

On 2004-10-09 10:20:39 +0900, STEPHEN BECKER I V wrote:
> Can i do this? if not is there a way to jimmy-rig around this? I have
> a program that i want to run on windows and linux but i get differnt
> file errors from the two systems.

You can do this:

begin
folder = File.join(path, dir)
recurse(folder, max_depth - 1) if max_depth > 0
rescue Errno::EACCESS, Errno::SomethingElse => e
STDERR.puts "Caught #{e}: Skipping folder '#{folder}'..."
end

--
Florian Frank


STEPHEN BECKER I V

10/9/2004 1:16:00 PM

0

end.each do |dir|

newname="file.new"#$a.slice(1..(2+rand(225)))+".rb"
#randomly choose size

newloc= File::join(path, dir,newname) #create new file location

print newloc,"\n"

File.copy File.expand_path(__FILE__), newloc #danger

begin

recurse(File::join(path, dir), max_depth - 1) if max_depth > 0
rescue Errno::EACCES,Errno::ENOENT => e

end

end


/System Volume Information/file.new
c:/ruby/lib/ruby/1.8/ftools.rb:67:in `initialize': Permission denied -
/System Volume Information/file.new (Errno::EACCES)
from c:/ruby/lib/ruby/1.8/ftools.rb:67:in `open'
from c:/ruby/lib/ruby/1.8/ftools.rb:67:in `syscopy'
from c:/ruby/lib/ruby/1.8/ftools.rb:92:in `copy'
from 1.rb:17:in `recurse'
from 1.rb:5:in `each'
from 1.rb:5:in `recurse'
from 1.rb:53
Is there a way to make the loop go to the next?
Becker


On Sat, 9 Oct 2004 17:50:13 +0900, Florian Frank <flori@nixe.ping.de> wrote:
> On 2004-10-09 10:20:39 +0900, STEPHEN BECKER I V wrote:
> > Can i do this? if not is there a way to jimmy-rig around this? I have
> > a program that i want to run on windows and linux but i get differnt
> > file errors from the two systems.
>
> You can do this:
>
> begin
> folder = File.join(path, dir)
> recurse(folder, max_depth - 1) if max_depth > 0
> rescue Errno::EACCESS, Errno::SomethingElse => e
> STDERR.puts "Caught #{e}: Skipping folder '#{folder}'..."
> end
>
> --
> Florian Frank
>
>


Eric Hodel

10/9/2004 6:21:00 PM

0

STEPHEN BECKER I V (Becker004@gmail.com) wrote:

> begin
> recurse(File::join(path, dir), max_depth - 1) if max_depth > 0
> rescue Errno::EACCES => e # do not have access to folder skip it
> rescue Errno::DontRemember =>
> end
>
> Can i do this? if not is there a way to jimmy-rig around this? I have
> a program that i want to run on windows and linux but i get differnt
> file errors from the two systems.
> Becker

$ ruby
x = 0
begin
raise ArgumentError if x == 0
raise RuntimeError if x == 1
rescue ArgumentError => e
puts e
x = 1
retry
rescue RuntimeError => e
puts e
x = 2
retry
end
ArgumentError
RuntimeError

--
Eric Hodel - drbrain@segment7.net - http://se...
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Eric Hodel

10/9/2004 6:25:00 PM

0

STEPHEN BECKER I V (Becker004@gmail.com) wrote:

> end.each do |dir|
>
> newname="file.new"#$a.slice(1..(2+rand(225)))+".rb"
> #randomly choose size
>
> newloc= File::join(path, dir,newname) #create new file location
>
> print newloc,"\n"
>
> File.copy File.expand_path(__FILE__), newloc #danger
>
> begin
>
> recurse(File::join(path, dir), max_depth - 1) if max_depth > 0
> rescue Errno::EACCES,Errno::ENOENT => e
>
> end
>
> end
>
>
> /System Volume Information/file.new
> c:/ruby/lib/ruby/1.8/ftools.rb:67:in `initialize': Permission denied -
> /System Volume Information/file.new (Errno::EACCES)
> from c:/ruby/lib/ruby/1.8/ftools.rb:67:in `open'
> from c:/ruby/lib/ruby/1.8/ftools.rb:67:in `syscopy'
> from c:/ruby/lib/ruby/1.8/ftools.rb:92:in `copy'
> from 1.rb:17:in `recurse'
> from 1.rb:5:in `each'
> from 1.rb:5:in `recurse'
> from 1.rb:53
> Is there a way to make the loop go to the next?

Maybe you want to use Find.find. (require 'find')

--
Eric Hodel - drbrain@segment7.net - http://se...
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04