大虾们:
  假设我有一个d:\test文件夹
  我要判断这个test文件夹里有没有test.txt文件?
代码怎么写?详细点!

解决方案 »

  1.   

    if FileExists('d:\test\test.txt') then
      

  2.   

    FileExists(PathStr(路径)+' 文件名')  这个结果是布尔类型的
      

  3.   

    if FileExists('d:\test\test.txt') then
       showmessage('found');
      

  4.   

    用FindFirst函数
    例如:
    procedure TForm1.Button1Click(Sender: TObject);var
      sr: TSearchRec;
      FileAttrs: Integer;
    begin
      StringGrid1.RowCount := 1;
      if CheckBox1.Checked then
        FileAttrs := faReadOnly
      else
        FileAttrs := 0;
      if CheckBox2.Checked then
        FileAttrs := FileAttrs + faHidden;
      if CheckBox3.Checked then
        FileAttrs := FileAttrs + faSysFile;
      if CheckBox4.Checked then
        FileAttrs := FileAttrs + faVolumeID;
      if CheckBox5.Checked then    FileAttrs := FileAttrs + faDirectory;
      if CheckBox6.Checked then
        FileAttrs := FileAttrs + faArchive;
      if CheckBox7.Checked then    FileAttrs := FileAttrs + faAnyFile;  if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then  begin
        with StringGrid1 do
        begin
          if (sr.Attr and FileAttrs) = sr.Attr then
          begin
            Cells[1,RowCount-1] := sr.Name;
            Cells[2,RowCount-1] := IntToStr(sr.Size);
          end;
          while FindNext(sr) = 0 do
          begin
            if (sr.Attr and FileAttrs) = sr.Attr then
            begin
            RowCount := RowCount + 1;
            Cells[1, RowCount-1] := sr.Name;        Cells[2, RowCount-1] := IntToStr(sr.Size);
            end;
          end;
          FindClose(sr);
        end;
      end;
    end;