program filefind;
Uses sysutils;
var directory : string;
var progname : string;
// ============================================================================
// Functions
// ============================================================================
procedure Usage(mesg : string);
begin
Writeln('Usage: ' + progname + ' directory');
Writeln(mesg);
end;
procedure traverse(directory : string);
var curdir1, curdir2 : string;
Info : TSearchRec;
pfile : string;
begin
curdir1 := GetCurrentDir;
chdir(directory);
curdir2 := GetCurrentDir;
FindFirst(directory + '/*', faAnyFile or faHidden, Info);
repeat
if ((Info.name <> '..') and (Info.name <> '.'))
then
begin
pfile := curdir2 + '/' + Info.name;
Writeln(pfile);
if (DirectoryExists(pfile))
then
traverse(pfile)
end
until FindNext(Info) <> 0;
chdir(curdir1);
end;
procedure start_traverse(directory : string);
begin
Writeln(directory);
traverse(directory);
end;
// ============================================================================
// Main
// ============================================================================
begin
progname := ParamStr(0);
directory := ParamStr(1);
if (ParamCount = 1)
then
if DirectoryExists(directory)
then
start_traverse(directory)
else
Usage('ERROR: Not a directory : ' + directory)
else
Usage('ERROR: 1 argument expected');
end.