如何边历得到指定目录下的EXE和DLL文件
并显示到LISTBOX1控件中

解决方案 »

  1.   

    看帮助,findfirst,findnext,然后判断后缀即可
      

  2.   

    给你一个函数:procedure GetFileList(Files: TStrings; Folder, FileSpec: string; SubDir: Boolean = True);
    {
      获取文件名列表
      Files:用来保存返回的文件名列表
      Folder:需要扫描的文件夹
      FileSpec:文件名,支持通配符*和?
      SubDir:是否包含子目录下的文件
    }
    var
      SRec: TSearchRec; //Required for Find* functions.
      FFolder: string;
    begin
      FFolder := IncludeTrailingPathDelimiter(Folder);
      if FindFirst(FFolder + FileSpec, faAnyFile, SRec) = 0 then
      begin
        repeat
          if ((SRec.Attr and faDirectory) <> faDirectory) and (SRec.Name[1] <> '.') then
            Files.Add(FFolder + SRec.Name);
        until FindNext(SRec) <> 0;
        FindClose(SRec);
      end;  if SubDir then
        if FindFirst(FFolder + '*', faDirectory, SRec) = 0 then
        begin
          repeat
            if ((SRec.Attr and faDirectory) = faDirectory) and (SRec.Name[1] <> '.') then
              GetFileList(Files, FFolder + SRec.Name, FileSpec, SubDir);
          until FindNext(SRec) <> 0;
          FindClose(SRec);
        end;
    end;调用示例代码:
    GetFileList(slFile, 'C:\Program Files\CnPack\CnWizards', '.dll', False)
    GetFileList(slFile, 'C:\Program Files\CnPack\CnWizards', '.exe', False)
      

  3.   

    调用示例代码:
    GetFileList(slFile, 'C:\Program Files\CnPack\CnWizards', '.dll', False)
    GetFileList(slFile, 'C:\Program Files\CnPack\CnWizards', '.exe', False)
    //===============================
    //我得到当前可执行文件的路径:
    var
      ssname:string;
    begin
      ssname:=application.ExeName;
      GetFileList(slFile,ssname,'.dll',False);
      GetFileList(slFile,ssname,'.exe',False);
    end;
      

  4.   

    [错误] Unit1.pas(59): Undeclared identifier: 'slFile'
    [致命错误] Project1.dpr(4): Could not compile used unit 'Unit1.pas'
      

  5.   

    slFile 没有定义var
      slFile:TStrings;