• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

Opening a text file using wildcards

Hi,

I am trying to read a txt file using wildcards. My code is below, but I get an I/O error on the Reset procedure.
How can I use wildcards to open a textfile?

f: TextFile;
AssignFile (f, 'u:\EDS\vendors*');
Reset(f);


Thanks.
0
HabBoy
Asked:
HabBoy
  • 2
1 Solution
 
2266180Commented:
you cannot use wildcards. if not for anotehr reason, then for the logical one that wildard means zero or more. and you are trying to open ONE file. not zero, not two, not more, but EXACTLY ONE.

what you could do though is use findfirst and findnext (with wildcard suport) and open every found file separatly (not a good idea to keep them open through the search though)
0
 
2266180Commented:
something like:

var r:TSearchRec; f:textfile;
begin
  if findfirst( 'u:\EDS\vendors*',faAnyFile {$WARNINGS OFF}
                                  -faVolumeID-faSymLink {$WARNINGS ON}
               ,r)=0 then
  begin
    repeat
        if r.Attr and faDirectory <> faDirectory then
        begin
          assignfile(f,'u:\EDS\'+r.name);
          reset(f);
          // do whatever
          closefile(f);
        end;
    until findnext(r)<>0;
    findclose(r);
  end;
end;
0
 
HabBoyAuthor Commented:
Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now