Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->编程语言 ->Delphi ->正文

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

来源:Linuxdby.com 作者:Webmaster 时间:2007-06-05 点击: [收藏] [投稿]
 

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

 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:使用互斥对象让程序只运行一次   下一篇:tlistview使用--拖放操作

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号