遍历目录的源码求教
解决方案 »
- SQL语句导出EXCEL的问题
- 一个关于抓取其他程序网络封包的DLL工程源代码。我编译不能通过,请各位指教。
- 台湾正在搞国旗设计
- 一则笑话
- 如何在delphi 7中编写通过代理下载文件的程序?(急急急……)
- 放分!!要考试了~(3)
- [公告]请大家不要发重复的帖子;请在标题把问题描述清楚;不要随意发短消息;不得有不礼貌的言辞
- 从右往左截取N个字符!!!
- 我用Delphi开发了一个CGI多用户留言簿,支持免费申请。有兴趣的朋友请进。
- 我用DELPHI6编译完EXE文件和原工程文件怎么在别的机器里无法运行??
- 怎么通过SMTP发送邮件啊。。我看了好几个程序。怎么都不行啊。程序怎么写啊。急!!!
- 进程外Com如何保证Com只被实例化一次?
---- 1.1拷贝目录的递归辅助函数:DoCopyDir function DoCopyDir(sDirName:String;
sToDirName:String):Boolean;
var
hFindFile:Cardinal;
t,tfile:String;
sCurDir:String[255];
FindFileData:WIN32_FIND_DATA;
begin
//先保存当前目录
sCurDir:=GetCurrentDir;
ChDir(sDirName);
hFindFile:=FindFirstFile('*.*',FindFileData);
if hFindFile< >INVALID_HANDLE_VALUE then
begin
if not DirectoryExists(sToDirName) then
ForceDirectories(sToDirName);
repeat
tfile:=FindFileData.cFileName;
if (tfile='.') or (tfile='..') then
Continue;
if FindFileData.dwFileAttributes=
FILE_ATTRIBUTE_DIRECTORY then
begin
t:=sToDirName+'\'+tfile;
if not DirectoryExists(t) then
ForceDirectories(t);
if sDirName[Length(sDirName)]< >'\' then
DoCopyDir(sDirName+'\'+tfile,t)
else
DoCopyDir(sDirName+tfile,sToDirName+tfile);
end
else
begin
t:=sToDirName+'\'+tFile;
CopyFile(PChar(tfile),PChar(t),True);
end;
until FindNextFile(hFindFile,FindFileData)=false;
FindClose(hFindFile);
end
else
begin
ChDir(sCurDir);
result:=false;
exit;
end;
//回到原来的目录下
ChDir(sCurDir);
result:=true;
end;
var
i : integer;
begin
treeview1.Selected:=treeview1.Items.Item[0];
for i :=1 to treeview1.Items.Count do
begin
treeview1.SetFocus;
// showmessage(TreeView1.Selected.Text);
if treeview1.Selected.getFirstChild = nil then
treeview1.Selected:=treeview1.Selected.GetNext
else
treeview1.Selected:=treeview1.Selected.getFirstChild;
if (treeview1.Selected.GetNext = nil) and (treeview1.Selected.Parent <> treeview1.TopItem) then
treeview1.Selected:=treeview1.Selected.Parent.GetNext;
if (treeview1.Selected.GetNext = nil) and (treeview1.Selected.Parent = treeview1.TopItem) then
exit; if treeview1.Selected.Text = str then
exit;
end;
end;
sr: TSearchRec;
FileAttrs: Integer;
begin
StringGrid1.RowCount := 1;
if CheckBox1.Checked then
FileAttrs := faReadOnly
else
FileAttrs := 0;
if CheckBox2.Checked then
FileAttrs := FileAttrs + faHidden;
if CheckBox3.Checked then
FileAttrs := FileAttrs + faSysFile;
if CheckBox4.Checked then
FileAttrs := FileAttrs + faVolumeID;
if CheckBox5.Checked then FileAttrs := FileAttrs + faDirectory;
if CheckBox6.Checked then
FileAttrs := FileAttrs + faArchive;
if CheckBox7.Checked then FileAttrs := FileAttrs + faAnyFile; with StringGrid1 do
begin
RowCount := 0; if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then begin
repeat
if (sr.Attr and FileAttrs) = sr.Attr then
begin
RowCount := RowCount + 1;
Cells[1,RowCount-1] := sr.Name;
Cells[2,RowCount-1] := IntToStr(sr.Size);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
end;
SubFolder: boolean; FoundResult: TStrings; var Num: integer);
var
i, Count: integer;
SubDir: TStrings;
SearchRec: TSearchRec;
{Begin Local Function}
function IsValidDir(SearchRec: TSearchRec): integer;
begin
if (SearchRec.Attr <> 16) and (SearchRec.Name <> '.') and
(SearchRec.Name <> '..') then
Result := 0 {It's not dir}
else
if (SearchRec.Attr = 16) and (SearchRec.Name <> '.') and
(SearchRec.Name <> '..') then
Result := 1 {It's not root dir}
else Result := 2; {It's root dir}
end;
{End Local Function}
begin
if Trim(Mask) <> '' then
begin
if (FindFirst(Path + Mask, faAnyFile, SearchRec) = 0) then
begin
repeat
if IsValidDir(SearchRec) = 0 then
begin
Inc(Num);
FoundResult.Add(Path + SearchRec.Name);
end;
Application.ProcessMessages;
until (FindNext(SearchRec) <> 0);
end;
FindClose(SearchRec);
if SubFolder then
begin
SubDir := TStringList.Create;
if (FindFirst(Path + '*.*', faDirectory, SearchRec) = 0) then
begin
repeat
if IsValidDir(SearchRec) = 1 then SubDir.Add(SearchRec.Name);
Application.ProcessMessages;
until (FindNext(SearchRec) <> 0);
end;
FindClose(SearchRec);
Count := SubDir.Count - 1;
for i := 0 to Count do
SearchFile(Path + SubDir.Strings[i] + '\', Mask, true, FoundResult, Num);
FreeAndNil(SubDir);
end;
end;
end;