From: Paul Duncan Date: 2004-09-25T06:57:58+09:00 Subject: Re: Directory search --AJ3oM32U01nchLSz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * STEPHEN BECKER I V (Becker004@gmail.com) wrote: > I am writing a program to go in all the folders, then in to there > folders....=20 Hi Stephen, It looks like all you do is print out the directory name. This might be a bit closer to what you're looking for: def recurse(path, max_depth =3D 5) Dir::entries(path).select do |file| file !~ /^\./ && test(?d, File::join(path, file))=20 end.each do |dir|=20 puts File::join(path, dir) recurse(File::join(path, dir), max_depth - 1) if max_depth > 0 end end Hope this helps... > def dirsearch (coming_in) #declare coming_in is the directory to be searc= hed > print "\n\n\n",coming_in," line 2 \n\n\n" #testing > Dir.chdir(coming_in) #change to the directory > mainloc =3D Dir.getwd #new base > file =3D Array.new=20 >=20 > print "\n\n\n",mainloc," line 7 \n\n\n" #testing >=20 > loc =3D Dir.open(mainloc) #open the folder > loc.each {|x| file.push(x) } #get the folders and files >=20 > dir =3D Array.new=20 > count =3D file.size #amounts >=20 > if count=3D=3D0 then break end#check if there are any files > print "-----------list------------",count,"--" > while count>0 > if(!(file[count-1].include? ?.)) #for windows assume that file has an > extension and no folders have a . > reform =3D mainloc +'/'+ file[count-1] # create list of folders > print reform > dir.push(reform) > end > count-=3D1 > end > print "\n" > if !(dir.size=3D=3D0) then #check if any folders to go in to > many =3D dir.size-1; > while many>0=20 > print dir[many],"loop at 28th\n" > if(!(dir[many].nil?))then #having a problem with nil folders? any help? > dirsearch(dir[many])#call function with new directory > end > many-=3D1 > end > end > end >=20 > dirsearch("c:") # light the candle >=20 >=20 > i am using SciTE in windows XP. It just seems to be cutting out after > about 5 runs of the function. Am i writing over the same variables? > Becker >=20 --=20 Paul Duncan pabs in #ruby-lang (OPN IRC) http://www.pablotron.org/ OpenPGP Key ID: 0x82C29562 --AJ3oM32U01nchLSz Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQFBVJh3zdlT34LClWIRAppfAJ99TEp4afxH5gsD14dm+JLV+tFWbgCgkTtO O4UKunW68kPwl6a/QQDvbGw= =ap6y -----END PGP SIGNATURE----- --AJ3oM32U01nchLSz--