Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!usenet.ins.cwru.edu!ncoast!allbery From: allbery@NCoast.ORG (Brandon S. Allbery KB8JRR/KT) Newsgroups: comp.lang.perl Subject: Re: pwd in perl Message-ID: <1990Aug9.225658.11586@NCoast.ORG> Date: 9 Aug 90 22:56:58 GMT References: <1141@etnibsd.UUCP> Reply-To: allbery@ncoast.ORG (Brandon S. Allbery KB8JRR/KT) Followup-To: comp.lang.perl Organization: North Coast Public Access *NIX, Cleveland, OH Lines: 27 As quoted from <1141@etnibsd.UUCP> by vsh@etnibsd.UUCP (Steve Harris): +--------------- | while ($f = readdir(D)) { | next if $f eq '..'; # skip '..' | next if -l $f; # skip links (but do lstat!) | next unless -d _; # skip non-dirs | ($d,$i) = stat(_); # get dev, ino for dir | next unless ($d == $dc && $i == $ic); # match? | last outerloop if ($f eq '.'); # root dir? | unshift(@path,$f); # add dir to path | ($dc,$ic) = ($dp,$ip); # parent becomes next child | last; # exit readdir loop | } +--------------- How about mount points? I'm almost *never* in the root file system. You should also provide a way to get back where you were before you started; preferably, opendir() a string which is built incrementally ("../../.."...). I just use chop($cwd = `pwd`); myself. If it ever bothers me, I'll port Doug Gwyn's getcwd() to Perl. ++Brandon -- Me: Brandon S. Allbery VHF: KB8JRR/KT on 220 (soon others) Internet: allbery@NCoast.ORG Delphi: ALLBERY uunet!usenet.ins.cwru.edu!ncoast!allbery America OnLine: KB8JRR