TListView组件显示文件夹中的文件 (转)

TListView组件显示文件夹中的文件 (转)[@more@]

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;
如果是二级或一级目录的话,只要加上if filepath<>'' then
类似的判断就可以了,例如:makedir('设计规范','电子件','电路设计规范','');

 

注:在这里写的两个过程没有实现读取windows的图标,如果想实现这一功能的话要自己动手写了 ^_^


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752019/viewspace-983745/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10752019/viewspace-983745/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值