Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!think!cs.utexas.edu!uunet!mcsun!hp4nl!eurtrx!euraiv1!reino From: reino@cs.eur.nl (Reino de Boer) Newsgroups: comp.lang.pascal Subject: Re: FindFile & FindNext problems with TP 5.x Keywords: grrr Message-ID: <1989Nov14.073404.10271@cs.eur.nl> Date: 14 Nov 89 07:34:04 GMT References: <2961@iitmax.IIT.EDU> Organization: Erasmus Universiteit Rotterdam, dept. CS (Informatica) Lines: 79 bundalo@iitmax.IIT.EDU (Predrag S. Bundalo) writes: > I'm writing a program that needs to make two calls to > FINDFILE. The first time, I need to get the names of > all of the subdirectories in the current directory and > store that somewhere (stack). The next time, I need > to find all of the files (in the current directory) > that match a given pattern (paramstr(1)). program filefind; uses crt, dos; type link = ^cell; cell = record rec : searchrec; next : link end; var dirs : link; arg : string; procedure push( var srec : searchrec ); var p : link; begin new( p ); with p^ do begin rec := srec; next := dirs end; dirs := p end; procedure pop( var srec : searchrec ); var p : link; begin p := dirs; dirs := dirs^.next; srec := p^.rec; dispose( p ) end; procedure getdirs; var srec : searchrec; begin findfirst( '*.*', anyfile, srec ); while( doserror = 0 ) do begin if( ( srec.attr and directory ) = directory ) then if( srec.name[1] <> '.' ) then push( srec ); findnext( srec ) end; end; procedure getfiles( pattern : string ); var srec : searchrec; begin findfirst( pattern, anyfile, srec ); while( doserror = 0 ) do begin if( ( srec.attr and directory ) <> directory ) then writeln( srec.name ); findnext( srec ) end end; procedure showdirs; var srec : searchrec; begin while( dirs <> nil ) do begin pop( srec ); writeln( srec.name ) end end; procedure pause; begin write( 'press a key...' ); while( readkey = #0 ) do; writeln end; begin if( paramcount < 1 ) then begin writeln( 'usage: filefind ' ); halt( 1 ) end; arg := paramstr( 1 ); dirs := nil; getdirs; getfiles( arg ); pause; showdirs; pause end. Hope this helps -- reino -- Reino R. A. de Boer Erasmus University Rotterdam ( Informatica ) e-mail: reino@cs.eur.nl