Two rescues?

  • Thread starter STEPHEN BECKER I V
  • Start date
S

STEPHEN BECKER I V

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
 
F

Florian Frank

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
 
S

STEPHEN BECKER I V

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
 
E

Eric Hodel

--cf0hFtnykp6aONGL
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
begin
recurse(File::join(path, dir), max_depth - 1) if max_depth > 0=20
rescue Errno::EACCES =3D> e # do not have access to folder skip it=20
rescue Errno::DontRemember =3D>
end =20
=20
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 =3D 0
begin
raise ArgumentError if x =3D=3D 0
raise RuntimeError if x =3D=3D 1
rescue ArgumentError =3D> e
puts e
x =3D 1
retry
rescue RuntimeError =3D> e
puts e
x =3D 2
retry
end
ArgumentError
RuntimeError

--=20
Eric Hodel - (e-mail address removed) - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


--cf0hFtnykp6aONGL
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQFBaCwkMypVHHlsnwQRAi+TAKCV3+J9fepwjstJHbQH2uxLdURc0ACgpsTx
qndGqJiwEC0SEvAgM2gy+kw=
=tzWx
-----END PGP SIGNATURE-----

--cf0hFtnykp6aONGL--
 
E

Eric Hodel

--2VXyA7JGja7B50zs
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
end.each do |dir|
=20
newname=3D"file.new"#$a.slice(1..(2+rand(225)))+".rb"
#randomly choose size
=20
newloc=3D File::join(path, dir,newname) #create new file location
=20
print newloc,"\n"
=20
File.copy File.expand_path(__FILE__), newloc #danger
=20
begin
=20
recurse(File::join(path, dir), max_depth - 1) if max_depth > 0=20
rescue Errno::EACCES,Errno::ENOENT =3D> e=20
=20
end
=20
end
=20
=20
/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')

--=20
Eric Hodel - (e-mail address removed) - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


--2VXyA7JGja7B50zs
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQFBaCzkMypVHHlsnwQRAliyAKDNv8SFI7ljIHgnYXhpItfCna+vBgCg4nQT
dYZrebXLxK8eY1YOUp0bB1g=
=4OCB
-----END PGP SIGNATURE-----

--2VXyA7JGja7B50zs--
 

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
474,159
Messages
2,570,879
Members
47,417
Latest member
DarrenGaun

Latest Threads

Top