How about
1) A neatly formatted program, so those you are asking for help can read it easily. I'll rewrite it below for you.
2) A clear statement of what computer and O/S you are working on.
If it is a DOS/Windows machine, then
mydir='/usr/local/';
should be
MyDir = '\usr\local';
3) I am unfamiliar with the procedure
findfiles
Why don't you document it clearly.
4) Do you get a better result if you omit the middle man
alphafile, and use text directly?
5) I believe a statement
A := B = C;
is always an error. See my note below.
HF
Luis Rivera wrote:
Hello!
I'm trying to implement a procedure and a function involving findfiles, which, afaik, can do path search.
One thing at a time. First is the function. A sample would be
--snip-- program FindFilesTest;
uses GPC, FileUtils;
type alphafile=text; var nameoffile: string; filename: alphafile; const mydir='/usr/local/';
function aopenin(var a:alphafile):boolean; begin if ioresult=0 then assign(a,trim(nameoffile)); findfiles(mydir,a,false,reset,nil); aopenin:=ioresult=0; end;
begin WriteLn ('Enter file name to type: '); ReadLn (nameoffile); if aopenin(alphafile) then WriteLn(nameoffile) else Writeln('sorry, search failed'); end.
--snip--
The compiler bites me back saying:
syntax error before reset extra comma
Beats my why.
Thanks in advance,
========================================
program FindFilesTest;
uses GPC, FileUtils;
type AlphaFile = Text;
var NameOfFile: string; FileName: AlphaFile;
const MyDir='\usr\local';
function AOpenIn(var A: AlphaFile): Boolean;
begin if IORresult = 0 then Assign(A, Trim(NameOfFile)); FindFiles(MyDir, A, False, Reset, nil); AOpenIn := (IOResult = 0); { NOTE THE ADDED () } end;
begin WriteLn('Enter file name to type: '); ReadLn(NameOfFile); if AOpenIn(AlphaFile) then WriteLn(NameOfFile) else Writeln('Sorry, search failed.'); end.