Luis Rivera a écrit :
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
should be aopenin(filename)
WriteLn(nameoffile) else Writeln('sorry, search failed'); end.
Declaring the text file as filename is very confusing: this is certainly the source of your errors: you confuse a file and its name.
The errors are seen by looking to the declarations
type TStringProc = procedure (const s: String);
procedure FindFiles (const Directory, Mask: String; MainDirFirst: Boolean; FileAction, DirAction: TStringProc); attribute (iocritical);
in the call of findfiles there are two errors:
1) a is a file, not a string (Mask)
2) reset has for parameter a file, not a string.
You might want to declare a FileAction procedure with a string parameter (nameoffile): probably you would include in it the assign which is before findfiles in your program and the reset
Notice that if there are multiple files found, you will have an error because you then try to reopen a file (a) which has not been closed: findfiles apply FileAction on all files which match Mask. You can close the file inside FileAction, but beware not to confuse nameoffile as a parameter of FileAction and as a global variable: if you give two different names and assign the global name to the parameter inside FileAction you can recover at the end the last nameoffile found.
Maurice
PS:
A := B = C; is correct in Pascal, weird but correct.