怎么去一文件夹下所有文件夹和子文件夹的名称?
在线等ing!
在线等ing!
解决方案 »
- BrightnessChange(form1.Image1.Picture.Bitmap, TrackBarBrightnessChange.value, form1.ProgressBar1);
- 新年新气象,祝各位在新的一年里,分多多,RMB多多!
- bde与ado 的比较
- 各位帮忙:如何用OLE 控制word的页面设置
- 我的托盘程序让系统无法关机!·!··#·!#·!##·¥
- 超难问题!如何在一个程序中得到另一个程序中的datagrid的数据!
- dbgrid和stringgrid哪个更快
- 如何listview改变columnheader颜色
- 请看问题代码
- 怎样将临时表中的数据一次过写进数据库中?
- 请问这个SQL语句应该怎么写?
- 打印问题请教各位!
var
mydir : TSearchRec;//记录文件情况
begin
Memo1.Clear;
if FindFirst('d:\tools\*.*',faDirectory,mydir) = 0 then
begin
Memo1.Lines.Add(mydir.Name);//可以把目录名记录在mystrings中,以后再用
while FindNext(mydir) = 0 do
begin
Memo1.Lines.Add(mydir.Name);
end;
end;
findclose(mydir);
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ShlObj;type
TMainForm = class(TForm)
TV: TTreeView;
btnInit: TButton;
edtPath: TEdit;
Label1: TLabel;
btnSelectDir: TButton;
procedure btnInitClick(Sender: TObject);
procedure btnSelectDirClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
MainForm: TMainForm;procedure InitTree(TreeNodes:TTreeNodes;ParentNode:TTreeNode;Path:AnsiString);
implementation{$R *.dfm}procedure InitTree(TreeNodes:TTreeNodes;ParentNode:TTreeNode;Path:AnsiString);
var
wfd:WIN32_FIND_DATA;
hdl:THandle;
Node:TTreeNode;
begin
Windows.ZeroMemory(@wfd,sizeof(WIN32_FIND_DATA));
hdl := Windows.FindFirstFile(PAnsiChar(Path + '*.*'),wfd);
if hdl <> INVALID_HANDLE_VALUE then
begin
//添加找到的第一个文件
if (AnsiString(wfd.cFileName) <> '.') and (AnsiString(wfd.cFileName) <> '..') then
begin
Node := TreeNodes.AddChild(ParentNode,wfd.cFileName);
//如果是目录,则递归添加子目录
if (wfd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY then
begin
InitTree(TreeNodes,Node,Path + wfd.cFileName + '\');
end;
end; Windows.ZeroMemory(@wfd,sizeof(WIN32_FIND_DATA));
while Windows.FindNextFile(hdl,wfd) do
begin
//添加找到的文件
if (AnsiString(wfd.cFileName) <> '.') and (AnsiString(wfd.cFileName) <> '..') then
begin
Node := TreeNodes.AddChild(ParentNode,wfd.cFileName);
//如果是目录,则递归添加子目录
if (wfd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY then
begin
InitTree(TreeNodes,Node,Path + wfd.cFileName + '\');
end;
end; Windows.ZeroMemory(@wfd,sizeof(WIN32_FIND_DATA));
end;
Windows.FindClose(hdl);
end;
end;procedure TMainForm.btnInitClick(Sender: TObject);
var
Path:AnsiString;
Node:TTreeNode;
begin
TV.Items.Clear; Path := edtPath.Text;
if (Path <> '') and (DirectoryExists(Path)) then
begin
if not IsPathDelimiter(Path,Length(Path)) then
begin
Path := Path + '\';
end;
Node := TV.Items.AddChild(NIL,Copy(Path,1,Length(Path) - 1));
InitTree(TV.Items,Node,Path);
end;
end;procedure TMainForm.btnSelectDirClick(Sender: TObject);
var
bi:BROWSEINFO;
Path:array[0..MAX_PATH] of char;
il:PITEMIDLIST;
begin
Windows.ZeroMemory(@bi,sizeof(BROWSEINFO));
bi.hwndOwner := Self.Handle;
bi.pidlRoot := NIL;
bi.lpszTitle := '请选择一个目录';
bi.pszDisplayName := Path;
bi.lpfn := NIL;
bi.lParam := 0;
bi.iImage := 0;
il := SHBrowseForFolder(bi);
if il <> NIL then
begin
if SHGetPathFromIDList(il,Path) then
begin
edtPath.Text := Path;
end;
end;
end;end.
////////////////
文件历遍