有一个程序需要从若干个(程序中数量为为变量N,长整型)文件名有序文件中读取文件,但其中有一些文件不存在,如何跳过?
代码段如下(n,a均为已知):for i := 1 to n do begin
    b[i] := a - i + 1;
    str(b[i],c[i]);
d[i] := 't20100825_' + c[i] + '.htm';
    Assign(input,d[i]);
    Reset(input);
    for j := 1 to 582 do readln;
read (m[i]);
    read (e[i]);
    close(input);
end;

解决方案 »

  1.   

    其实是Free Pascal写的程序,语法我也只会turbo pascal,实在找不到TP或FP的板块,只好来这,至少还是pascal!
      

  2.   

    for i := 1 to n do begin
      b[i] := a - i + 1;
      str(b[i],c[i]);
    d[i] := 't20100825_' + c[i] + '.htm';
    if FileExists(d[i]) then
    begin
      Assign(input,d[i]);
      Reset(input);
      for j := 1 to 582 do readln;
    read (m[i]);
      read (e[i]);
      close(input);
    end;
    end;用FileExists判断下文件是否存在。
      

  3.   


    可是,我照你的方法修改后在lazarus里无法编译(win32bit,0.93版),软件提示:
    (18,18)Error:Identifier not found "FileExists"  (FileExists这行就在程序的第十八行)
    如何解决?好像你写的是Delpin代码吧……
      

  4.   

    文件开始加上 {$I- }
    reset(input); if ioresult=0 then
      begin
      文件存在才会到这里..
      end;