home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
NEWS
/
554
/
JUIN
/
WHERE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-10-07
|
3KB
|
101 lines
{─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 462 of 587
From : Raphael Vanney 2:320/7.0 02 Jun 93 00:41
To : Frank Livaudais
Subj : Tree?
────────────────────────────────────────────────────────────────────────────────
Hi !
FL>Is there a tree type function is pascal? I want to find all the
FL>directories on a given drive so i can search for files but am unsure of
FL>how to go about it, i can find files in given directories but i wanna
FL>search the whole drive, so is there a way to find out how many and what
FL>directories there are?
Here follows the source of a 'where' program :}
{$A-,B-,D+,E-,F-,I+,L-,N-,O-,R-,S-,V-}
{$M 16384,0,0}
uses DOS , Crt ;
var Mask : String[12] ;
t : DateTime ;
n : integer ;
Sortie : Text ;
as : string[5] ;
procedure Fouille_Rep( NomRep : PathStr ) ;
var s : SearchRec ;
begin
Write(NomRep);ClrEol;write(#13);
FindFirst(NomRep+'*.*',AnyFile,s);
while DosError=0 do
begin
if (s.name[1]<>'.') and ((s.attr and Directory)=Directory)
then Fouille_Rep(NomRep+s.name+'\');
FindNext(s)
end;
FindFirst(NomRep+Mask,AnyFile,s);
while DosError=0 do
with s do
begin
UnPackTime(time,t);
inc(n);
write (Sortie, name : 12,' ');
if (attr and Directory)<>Directory then
begin
as:=' ';
write(Sortie, size : 8);
if (attr and ReadOnly)=ReadOnly then as[2]:='R';
if (attr and Hidden )=Hidden then as[3]:='H';
if (attr and SysFile )=SysFile then as[4]:='S';
if (attr and Archive )=Archive then as[5]:='A';
write(Sortie, as)
end else write(Sortie, ' Rpertoire ');
write(Sortie, t.day:3,'/');
if t.month<10 then write(Sortie, '0');
write(Sortie, t.month,'/',t.year:4,' ',t.hour:2,':');
if t.min<10 then write(Sortie, '0');
write(Sortie, t.min);
writeln(Sortie, ' ',NomRep);
if KeyPressed then exit;
FindNext(s)
end
end;
var dir, nom, ext : string ;
begin
if paramcount<>1 then
begin
writeln(' - WHERE [disque:][repertoire]<nom_fichier>');
writeln(' jockers autoriss.');
writeln;
halt
end;
Assign(Sortie, '');
ReWrite(Sortie);
FSplit(ParamStr(1),dir,nom,ext);
if ext='' then ext:='.*';
if nom='' then nom:='*';
if dir[length(dir)]<>'\' then dir:=dir+'\';
{ notez que ce test est valable si dir='' (dir[0]=#0, <>'\') }
mask:=nom+ext;
write(Sortie, 'Recherche de '+mask);
if dir='\' then writeln(Sortie, ' dans tous les rpertoires')
else writeln(Sortie, ' dans '+dir);
writeln;
n:=0;
Fouille_Rep(dir);
if KeyPressed then writeln('Recherche interrompue par l''utilisateur.');
while KeyPressed do write(ReadKey,#8);
ClrEol;
writeln;
writeln(n,' fichier(s) trouv(s)');
Close(Sortie);
end.