From: Brian Candler Date: 2010-04-28T23:00:49+09:00 Subject: Re: navigate through folders Andrei Caragea wrote: > File.open('file.txt').each_line do |p| > > Dir::chdir("#{p}") > { > bunch of code > } > > What I want to do after this is to go up to /path1 or /path and run some > more code; and this is where I'm stuck. > > Can anyone point me in the right direction? Note that p contains a newline at the end, which I'd expect would give you an Errno::ENOENT. But if the chdir is successful then you can walk up a level using "..". Note that inside the block form of chdir this gives a warning. >> Dir.pwd => "/home/candlerb" >> Dir.chdir("/etc/fonts") { Dir.chdir(".."); puts Dir.pwd } (irb):8: warning: conflicting chdir during another chdir block /etc => nil Otherwise you could try: Dir.chdir(p) { .. some code .. } Dir.chdir("#{p}/..") { .. some more code .. } or take a look at the Pathname library >> require 'pathname' => true >> p = Pathname.new("/etc/fonts") => # >> p.parent.to_s => "/etc" -- Posted via http://www.ruby-forum.com/.