var
sr: TSearchRec;FindFirst(CurrDir,faAnyFile,sr);
      repeat
        case sr.Attr of
        faDirectory:    begin
                        //进行对目录的处理
                        end;
        faArchive:      begin
                        //进行对文件的处理
                        end;
        end; //end case
      until FindNext(sr) <> 0;

解决方案 »

  1.   

    unit FindFiles;interfaceuses
      Windows, Messages, SysUtils, Classes, FileCtrl;  procedure FindFilesInDir(const sDir, sExt: string; slFile: TStrings;
        bIncludeSubDir: boolean);
      
    implementationprocedure FindFilesInDir(const sDir, sExt: string; slFile: TStrings;
      bIncludeSubDir: boolean);
    var
      SearchRec: TSearchRec;
      sTmp, Dir: string;
    begin
      Dir := trim(sDir);
      if copy(Dir, length(Dir), 1) <> '\' then Dir := Dir + '\';
      if FindFirst(Dir + '*.*', faAnyfile, SearchRec) = 0 then
      begin
        repeat
          if (SearchRec.Name = '.') or (SearchRec.Name = '..') then
          begin
            ;
          end
          else if ((SearchRec.Attr and fadirectory) <> 0) and bIncludeSubDir then
          begin
            FindFilesInDir(Dir + SearchRec.Name, sExt, slFile, bIncludeSubDir);
          end
          else
          begin
            sTmp := UpperCase(ExtractFileExt(SearchRec.Name));
            if sTmp = '.' + UpperCase(sExt) then
              slFile.Add(Dir + SearchRec.Name);
          end;
        until FindNext(SearchRec) <> 0
      end;
      FindClose(SearchRec);
    end;end.
      

  2.   

    uses 
      FileCtrl, SysUtils; 把下面的FUNCTION家道你的程序里面看看. function IsEmptyFolder(fld:string):boolean; 
    var 
      sr:tsearchrec; 
      r:integer; 
    begin 
      fld:=IncludeTrailingBackSlash(fld); 
      result:=false; 
      if(DirectoryExists(fld))then 
      begin 
        result:=true; 
        r:=findfirst((fld+'*.*'),faAnyFile,sr); 
        while((r=0)and(result))do 
        begin 
          // Revision 2: 
          // checks for system folders "." and ".." that always exists 
          // inside an empty folder. 
          if((SR.Attr and faDirectory)<>0)then 
          begin 
            if((sr.name<>'.')and(sr.name<>'..'))then 
            begin 
              result:=false; 
            end; 
          end else 
          begin 
            result:=false; 
          end; 
          r:=findnext(sr); 
        end; 
        // Revision 1: 
        // this prevents compiler by using the API defined in windows unit, 
        // that will raise a compiler error like this: 
        // [Error]:Incompatible types: 'Cardinal' and 'TSearchRec' 
        sysutils.findclose(sr); 
      end; 
    end;  
      

  3.   

    我想直接用计时器响应,用几个api函数就可以搞定了!就是扫描磁盘有没有变动的函数!
      

  4.   

    如果只对你说的特定文件夹中是否有文件存在 有则列出文件名 而不考虑其
     下是不是还有文件夹的话  可以用TFileListBox控件(win3.1 下)
    *************************************************************
     在设计过程中直接把它放到窗体上 .Visible 设置为False 
     with FileListBox1 do begin
        Clear ;
        Directory := 指定目录 ;
        Mask := '*.*' ;
        if Count>0 then begin ...end
                   else begin ...end ;
        // Items[i] 单个引用文件名
        // Items.CommaText 所有文件名的组合
     end ;