如何判断一个文件夹下是否有文件存在?

解决方案 »

  1.   

    FindFirst函数:该函数功能为:查找目录下的第一个文件,并且创建内存控件使用。
      

  2.   

    FindFirst函数:该函数功能为:查找目录下的第一个文件,并且创建内存空间使用。
      

  3.   

    Function FinfFirst(Const Path:String;Attr:Word;var SearchRec:TSearchRec):Integer;
    TSearchRec=record
        Fill:array [1..21] of Byte;
        Attr:Byte;
        Time:Longint;
        Size:Longint;
        Name:string[12];
    end;
    其中Name为匹配的文件名。
    函数返回0,表示查找成功,否则返回DOS错误代码的负值。-18表示没有找到匹配的文件。
      

  4.   

    更正:上面的函数名写错了finffirst-->findfirst
         Attr为查找文件的属性
      

  5.   

    下面说明:C:\1这个目录是否存在txt文件.
    procedure TForm1.Button1Click(Sender: TObject);
    var
     SearchRec:tSearchRec;
     FindResult:integer;
    begin
    FindResult := FindFirst('C:\1\'+ '*.txt',FaAnyFile,SearchRec);
    if findresult=0 then
       showmessage('存在txt文件')
       else
       showmessage('不存在txt文件');
    end;
      

  6.   

    FileExists(const FileName: string): Boolean
      

  7.   

    FindFirst()和FindNext()会找到两个不是文件的东东,一是“.”,二是“..”,呵呵,要把这两个排除掉,因为任何一个文件夹,哪怕它是空的,这两个东东也存在
      

  8.   

    to hottey(蓝色的幽灵): *.*为什么不可以?
      

  9.   

    FindFrist
    findnext
    记得要释放seachrec的资源哟
      

  10.   

    to liugaqiong(may snow):
       *.*也是可以的了.不过我没有试过.SeaWave() 说的也许是正确的吧!你自己试试吧!程序并不复杂.程序后是要释放seachrec的资源:
       FindClose(SearchRec);
      

  11.   

    function TForm1.IsHasFile(const Path:string):boolean;//返回true代表有文件
    var
     sr: TSearchRec;
     Attr:integer;
     iResult:integer;
    begin
      result:=false;//初始化,假定没有文件
      Attr:=faAnyFile-faDirectory ;//可以为其它属性(具体见Delphi帮助)
      iResult:= FindFirst(Path+'\*.*',Attr,sr);//检测目录'G:\1\'下面是否有文件
      while iResult=0  do
         begin
            if (sr.Name <>'.') and (sr.Name <>'..') then //可以去掉
              result:=true;//代表有文件
           iResult:=FindNext(sr);
         end;
      FindClose(sr);end;
      

  12.   

    用Tfilelistbox控件,把他隐藏起来,并设置其路径,判断Tfilelistbox.items.count...