home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
PARADIS1
/
FINDFILE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-02-26
|
4KB
|
139 lines
(7477) Sat 22 Feb 92 0:43
By: Joy Mukherjee
To: Todd Zabel
Re: Finding A file
St:
---------------------------------------------------------------------------
@MSGID: 1:387/255 56b870b5
TZ>I am fairly new to TP and would like to develope a procedure that will
TZ>scan an entire drive for a file (something like NU Find File).
Program FindFile;
{ ========================================================================= }
{ }
{ DESCRIPTION: This program locates all files matching FILENAME on the }
{ current drive. It is a modification of the REDFIL.PAS }
{ program written by James C. Walker (found on CompuServe }
{ BPROGA TP4 library). Thank you Mr. Walker. }
{ }
{ SYNTAX: FindFile FILENAME }
{ (note that FILENAME may include DOS wildcards * and ?) }
{ }
{ HISTORY: 06/30/1988 Written by Paul L. Randall }
{ }
{ ========================================================================= }
Uses
Crt, Dos;
type
Str4 = string[4];
Str8 = string[8];
Var
SearchDir : String;
Found : boolean;
CompareFiles : boolean;
LocateFile : string;
Row : byte;
DateTimeRec : DateTime;
Function GetFileDate(Year : word;
Month : word;
Day : word) : Str8;
var
Temp1 : string[2];
Temp2 : string[2];
Temp3 : string[4];
begin { GetFileDate }
Str(Month:2,Temp1);
Str(Day:2,Temp2);
if Temp2[1] = ' ' then Temp2[1] := '0';
Str(Year:4,Temp3);
GetFileDate := Temp1 + '-' + Temp2 + '-' + Copy(Temp3,3,2)
end; { GetFileDate }
Function GetFileAttr(var SRec : SearchRec) : Str4;
begin { GetFileAttr }
GetFileAttr := ' ';
with SRec do
begin
if Attr and ReadOnly = ReadOnly then
GetFileAttr[1] := 'R';
if Attr and Hidden = Hidden then
GetFileAttr[2] := 'H';
if Attr and SysFile = SysFile then
GetFileAttr[3] := 'S';
if Attr and Archive = Archive then
GetFileAttr[4] := 'A'
end
end; { GetFileAttr }
Procedure ReadFiles(Dir : String);
Var
ch : char;
FileInfo : SearchRec;
begin
if CompareFiles then
begin
FindFirst(Dir + LocateFile,AnyFile,FileInfo);
While DosError = 0 do
begin
Found := TRUE;
UnPackTime(FileInfo.Time,DateTimeRec);
with DateTimeRec do
Writeln('Name : ', Dir + FileInfo.Name,
'':(46 - (Length(FileInfo.Name) + Length(Dir))),
' Date: ',GetFileDate(Year,Month,Day),
' Attr: ', GetFileAttr(FileInfo));
Row := Row + 1;
if Row = 25 then
begin
Write('Press any key to continue . . . ');
Repeat until KeyPressed;
Ch := ReadKey;
WriteLn;
Row := 1
end;
FindNext(FileInfo)
end;
CompareFiles := FALSE
end;
FindFirst(Dir + '*.*', AnyFile, FileInfo);
While DosError = 0 do
begin
If (FileInfo.Attr = Directory) and
(FileInfo.Name <> '.') and
(FileInfo.Name <> '..') then
begin
CompareFiles := TRUE;
ReadFiles(Dir + FileInfo.Name + '\');
Writeln (FileInfo.Name);
end;
FindNext(FileInfo)
end
end;
begin
if ParamCount <> 0 then
begin
Row := 1;
Found := FALSE;
LocateFile := ParamStr(1);
SearchDir := '\';
CompareFiles := TRUE;
ReadFiles(SearchDir);
if not Found then WriteLn('No such file !')
end else WriteLn('FINDFILE correct syntax is: FINDFILE FILENAME')
end.
Hope it helps...
* SLMR 2.1a # * Read Error : go back to school!
--- MsgToss 2.0 (r)
* Origin: Nul 512-615-NUL1 HST/V32b,615-NUL2, NUL3, 1.2Gig (1:387/255)
@PATH: 387/255 823 170/400 512/0 1007