TListView组件显示文件夹中的文件

时间:2010-03-05 18:49:29  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:g; Item: Tlistitem; IncludeFiles: boolean);varSearchRec: TSearchRec;begin  list.Items.BeginUpdate;//准备更新   list.Items.Clear;  //清空list内容   if Directory[length(Directory)] <> '' then //判断路径          D...
  正文:参见如下代码


procedure GetDirectories(list: TlistView; Directory: string; Item: Tlistitem; IncludeFiles: boolean);
var
SearchRec: TSearchRec;
begin
  list.Items.BeginUpdate;//准备更新
   list.Items.Clear;  //清空list内容
   if Directory[length(Directory)] <> '' then //判断路径
         Directory := Directory + '';  //设置路径
   if FindFirst(Directory + '*.*',faDirectory,SearchRec) = 0 then       begin
    repeat    
    if (SearchRec.Attr and faDirectory = faDirectory) and (SearchRec.Name[1] <> '.') then  
    begin
      if (SearchRec.Attr and faDirectory > 0) then                               begin  Item := list.Items.Add;  //增加item
                                        item.Caption:=SearchRec.Name;
        item.ImageIndex:=6;
      end;
      GetDirectories(list,Directory + SearchRec.Name,Item,IncludeFiles);
    end
    else
    if IncludeFiles then
    if SearchRec.Name[1] <> '.' then
    begin
      item:=list.Items.Add;
      item.Caption:=SearchRec.Name;
      item.ImageIndex:=6;
    end;
    until FindNext(SearchRec) <> 0;
    //FindClose(SearchRec);
               end;
  list.Items.EndUpdate;
end;

定义Directory:


procedure makedir(modulname,pathname,dirname,filepath:string);
//创建目录(共4级,朋友如果觉得用得上的话,可以自己加参数)
begin
  try
    if not directoryexists(frootpath+modulname) then
    createdir(FRootPath+modulname);
    if not DirectoryExists(FRootPath+modulname+''+pathname) then
    createdir(FRootPath+modulname+''+pathname);
    if not directoryexists(FRootPath+modulname+''+pathname+'
'+dirname) then
    createdir(FRootPath+modulname+''+pathname+''+dirname);
    if filepath<>'' then
    if not directoryexists(FRootPath+modulname+''+pathname+''+dirname+''+filepath) then
    createdir(FRootPath+modulname+''+pathname+''+dirname+'
'+filepath)
    except
      On E:Exception do begin
        abort;
      end;
    end;
    banjin.N21.Enabled:=true;
    liucheng.MenuItem1.Enabled:=true;
    yanzheng.N21.Enabled:=true;
    banjin.SpeedButton1.Enabled:=true;
    liucheng.SpeedButton1.Enabled:=true;
    yanzheng.SpeedButton1.Enabled:=true;
    banjin.toolbutton1.Enabled:=true;
    liucheng.toolbutton1.Enabled:=true;
    yanzheng.toolbutton1.Enabled:=true;
    if filepath='' then
    filespath:=FRootPath+modulname+''+pathname+''+dirname+'
'+filepath else
    filespath:=FRootPath+modulname+''+pathname+''+dirname+'
'+filepath+'';
    banjin.StatusBar1.Panels[0].Text:='你目前所在的位置:'+filespath;
    liucheng.StatusBar1.Panels[0].Text:='你目前所在的位置:'+filespath;
    yanzheng.StatusBar1.Panels[0].Text:='你目前所在的位置:'+filespath;
  end;

"TListView组件显示文件夹中的文件"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/13062.html


关键字:

关于《TListView组件显示文件夹中的文件》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td