TListView组件显示文件夹中的文件
2003-08-13 10:34
232 查看
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的图标,如果想实现这一功能的话要自己动手写了 ^_^
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的图标,如果想实现这一功能的话要自己动手写了 ^_^
相关文章推荐
- mac 上显示隐藏文件/文件夹
- 访问外部存储中的数据库文件,使用CursorAdapter显示在ListView组件上
- MacOS X自动切换是否显示所有隐藏文件和文件夹
- 如何MyEclipse中显示WEB-INF文件夹下的classes目录以及目录中的class文件
- 修复TortoiseGit文件夹和文件状态图标不显示问题
- 无法显示隐藏文件和文件夹
- 在Eclipse中显示.project, .classpath, .gitignore文件和.setting文件夹
- 在 ListView 中显示文件和文件夹系统图标的实现类
- 显示文件或文件夹的属性
- secureCRT 字体颜色、文件夹和文件显示的颜色区别开解决办法
- Mac下如何显示隐藏文件/文件夹
- TortoiseSVN文件夹及文件图标不显示解决方法
- 在SD卡指定文件夹下搜索ogg文件,列表显示,点击播放
- TortoiseSVN文件夹及文件图标不显示解决办法
- 修复TortoiseGit文件夹和文件图标不显示问题
- TortoiseSVN文件夹及文件图标不显示解决方法
- php 遍历显示文件夹下所有目录、所有文件的函数,没有分页的代码
- php 遍历显示文件夹下所有目录、所有文件的函数,没有分页的代码
- 使用BeyondCompare比较文件夹下的文件时,相同的文件内容,但显示为不相同
- 显示所有文件和文件夹"失效 解决无法显示所有文件和文件夹