| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 761 人关注过本帖
标题:目录的遍历问题
只看楼主 加入收藏
Sewim
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2006-3-7
收藏
 问题点数:0 回复次数:3 
目录的遍历问题
大家好
本人在程序中需要从TDirectoryListBox 中对当前目录下的所有子目录能从程序中调用访问,不知如何进行!

请指教!
搜索更多相关主题的帖子: 遍历 目录 指教 访问 
2006-03-07 12:32
Sewim
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2006-3-7
收藏
得分:0 
欢迎各位加入"程序员讨论群":17807670
2006-03-07 13:16
aerefasdf
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2006-3-2
收藏
得分:0 

//ListDirs函数找出Path目录下所有子文件夹,保存于List中
function ListDirs(Path: string; List: TStringList): Integer;
var
FindData: TWin32FindData;
FindHandle: THandle;
FileName: string;
AddToList: Boolean;
begin
Result := 0;
AddToList := Assigned(List);
if Path[Length(Path)] <> '\' then
Path := Path + '\';
Path := Path + '*.*';
FindHandle := Windows.FindFirstFile(PChar(Path), FindData);
while FindHandle <> INVALID_HANDLE_VALUE do
begin
FileName := StrPas(FindData.cFileName);
if (FileName <> '.') and (FileName <> '..') and
((FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) <> 0) then
begin
Inc(Result);
if AddToList then
begin
List.Add(extractFilepath(Path)+FileName);
ListDirs(extractFilepath(Path)+FileName,List);
end;
end;
if not Windows.FindNextFile(FindHandle, FindData) then
FindHandle := INVALID_HANDLE_VALUE;
end;
Windows.FindClose(FindHandle);
end;


procedure TForm1.Button1Click(Sender: TObject);
var sl:TStringList;
begin
sl:=TStringList.Create;
ListDirs('E:\',sl);
showmessage(sl.Text);
sl.free;
end;


密码啊,是多少? 有事上论坛联系 www.
2006-03-07 21:42
Sewim
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2006-3-7
收藏
得分:0 
谢谢!aerefasdf
2006-03-08 09:56
快速回复:目录的遍历问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018305 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved