//一个遍历所有硬盘的所有目录的实例源码: unit Unit1; interface uses
Windows, Messages,SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, ImgList, ExtCtrls; type
TForm1 = class(TForm)
Button3: TButton;
TreeView: TTreeView;
Edit1: TEdit;procEDure Button3Click(Sender: TObject);
private
{ Private declarations }
public
procedure CreateDirectoryTree(RootDir, RootCaption: string);
end;var
Form1: TForm1; implementation{$R *.DFM}
procedure TForm1.CreateDirectoryTree(RootDir, RootCaption: string);
procedure AddSubDirToTree(RootNode: TTreeNode);
var
SearchRec: TSearchRec;
Path: string;
Found: integer;
begin
Path := PChar(RootNode.Data) + '\*.*';
//showmessage(Path);
Found := FindFirst(Path, faAnyFile, SearchRec);
while Found = 0 do
begin
if (SearchRec.Attr = faDirectory) and (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
AddSubDirToTree(TreeView.Items.AddChildObject(RootNode, SearchRec.Name,
PChar(PChar(RootNode.Data) + '\' + SearchRec.Name)));
Found := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
begin
//TreeView.Items.Clear;
AddSubDirToTree(TreeView.Items.AddObject(nil, RootCaption, PChar(RootDir)));
end;procedure TForm1.Button3Click(Sender: TObject);
var
i:integer;
abc:Tstrings;
s:string;
begin
abc:=TStringlist.Create;
for i:=0 to 23 do begin
s := Chr(65+i)+':\';
// if GetDriveType(PChar(s))= DRIVE_cdrom then
if directoryexists(s) then
begin
s:=copy(s,0,2) ;
abc.Add(s);
end;
end;
for i:=0 to abc.Count-1 do
BEGIN
S:=abc.strings[i];
CreateDirectoryTree(S, '['+s+'\]');
END
end;
end.
解决方案 »
- 【请教】图形问题!
- 请教高手关于Dll的问题?
- dbf数据库不支持中文字段,怎么办啊?
- 如何在Tedit中自定双精度型字段变量的显示格式?
- 窗体合并问题
- 想实现一个思路,不知道怎么做,就是要实现按一个热键,然后就调用屏幕保护程序或者直接黑屏也行。
- 用unidac的unitable手动连接firebird数据库 提示no permission for read select access to table
- 紧急求助!关于用dll来建立ado连接的问题与dll解决重复登录问题。请大家指教。
- 怎么用BDE连接Foxpro数据库,请说明详细配置过程,我搞了N次就是不爽,谢谢!!
- 当动态创建组件后......
- 【求助】我知道有个delphi万一博客,有没有像这样的VC++博客啊?
- 运行不报错,点击按钮却没反应,请问是哪里错了呢?
并未有给AddSubDirToTree(RootNode: TTreeNode)过程传参数,执行AddSubDirToTree时怎么会有值呢?
while Found = 0 do
begin
Application.ProcessMessages;if (SearchRec.Attr = faDirectory) and (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
高手请把#4楼这个问题也解释解释呗?
TreeView.Items.AddObject(nil, RootCaption, PChar(RootDir))传进的