得到指定目录中所有文件的信息(文件名、时间、大小、属性),并在listView中显示?(listView的viewStyle为vsReport)

解决方案 »

  1.   

    你用findFirst,findnext,在其中可以得到你要的信息,然后读到listView
      

  2.   

    uses shellapi; //that unit is necessaryprocedure getshellinfo(a:tfilename;var name,typ:string;var icon:ticon;var attr:integer);
    var 
      info : tshfileinfo;
    begin
         // get shell-info about the specified file (in "a")
         {parameters :
              name : receives the explorer-style filename (e.g. without extension)
              typ  : receives the explorer-style typename of the file (e.g. "anwendung" for an exe in german win95)
              icon : will content the icon which is shown in the explorer for that file (this is slower than extracticon !!!!)
              attr : gets the explorer-attributes of the file, these are (ripped from win32-help):
                   sfgao_cancopy the specified file objects or folders can be copied (same value as the dropeffect_copy flag).
                   sfgao_candelete the specified file objects or folders can be deleted.
                   sfgao_canlink it is possible to create shortcuts for the specified file objects or folders (same value as the dropeffect_link flag).
                   sfgao_canmove the specified file objects or folders can be moved (same value as the dropeffect_move flag).
                   sfgao_canrename the specified file objects or folders can be renamed.
                   sfgao_capabilitymask mask for the capability flags.
                   sfgao_droptarget the specified file objects or folders are drop targets.
                   sfgao_haspropsheet the specified file objects or folders have property sheets.               a file object's display attributes may include zero or more of the following values:               sfgao_displayattrmask mask for the display attributes.
                   sfgao_ghosted the specified file objects or folders should be displayed using a ghosted icon.
                   sfgao_link the specified file objects are shortcuts.
                   sfgao_readonly the specified file objects or folders are read-only.
                   sfgao_share the specified folders are shared.               a file object's contents flags may include zero or more of the following values:               sfgao_contentsmask mask for the contents attributes.
                   sfgao_hassubfolder the specified folders have subfolders (and are, therefore, expandable in the left pane of windows explorer).               a file object may have zero or more of the following miscellaneous attributes:               sfgao_filesystem the specified folders or file objects are part of the file system (that is, they are files, directories, or root directories).
                   sfgao_filesysancestor the specified folders contain one or more file system folders.
                   sfgao_folder the specified items are folders.
                   sfgao_removable the specified file objects or folders are on removable media.
                   sfgao_validate validate cached information.}
         fillchar(info,sizeof(tshfileinfo),0);
         shgetfileinfo(pchar(a),0,info,sizeof(info),shgfi_displayname or shgfi_typename or
         shgfi_icon or shgfi_attributes);
         with info do begin
              name := szdisplayname;
              typ  := sztypename;
              icon.handle := hicon;
              attr        := dwattributes;
         end;
    end;
      

  3.   

    楼上老兄,我是要将文件信息加入listview中
      

  4.   

    给个我曾经写过的例程给你,希望可以解决你的问题.//读入某个目录下的所有某类文件至一个StringList
    //PathName:所读取的目录名称 如 c:\test
    //FileType:所读取的文件类型 如 *.* A2003??.*等等
    //Rslist:读取返回的Stringlist调用时事先定义一个变量为TStringlist类型
    var 
      Example:Tstringlist;调用时: 
      GetFilesName('c:\test','*.txt',Example);//子程序如下: 
    //
    procedure GetFilesName(PathName:string;FileType:string;var 
    RsList:Tstringlist);
    var
      SearchFile:TSearchRec;
      Succeed:boolean;
    begin
      RsList.Free;
      RsList:=Tstringlist.Create;
      Succeed:=True;
      if (not DirectoryExists(PathName)) or
         (not FindFirst(PathName+FileType,faAnyFile,Searchfile)=0)
      then Succeed:=False;
      if Succeed then
        begin
          RsList.Append(PathName+'\'+Trim(SearchFile.Name));
          while FindNext(Searchfile) =0 do
          RsList.Append(PathName+'\'+Trim(SearchFile.Name));
          FindClose(SearchFile);
        end
      else
        begin
          RsList.Append('No Files!');
          FindClose(SearchFile);
        end;
    end;