// ============================================================================
// Create
// name : Andre Rikkert de Koe date: Mar 2018
// descr : filefind
// This is a demo of programming in the Pascal language.
// Its part of a project to implement a program to create a directory
// tree similar to the output of the Unix find program.
// EUID : Any user who has read access to all the files being searched for.
// run : interactive
//
// Changes
// name : date:
// descr : short description
//
// ============================================================================
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.