procedure TForm1.N1Click(Sender: TObject);
var
I: Integer; procedure GetFileDir(S: string);
var
Found: Integer;
SearchRec: TSearchRec;
begin
Found := FindFirst(S + '\*.*', faAnyFile, SearchRec);
while Found = 0 do
begin
ListView1.Items.Add;
ListView1.Items[I].Caption := S + '\' + SearchRec.Name;
Inc(I);
if FileGetAttr(S + '\' + SearchRec.Name) = faDirectory then
GetFileDir(S + '\' + SearchRec.Name);
Found := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;begin
I := 0;
GetfileDir('C:');
end;我想把C盘里所以的目录和文件全部都加入在listview控件里面...可是为什么以上代码不行.. 还有一个问题就是listview里面可以加入多少条..有没有限制...
var
I: Integer; procedure GetFileDir(S: string);
var
Found: Integer;
SearchRec: TSearchRec;
begin
Found := FindFirst(S + '\*.*', faAnyFile, SearchRec);
while Found = 0 do
begin
ListView1.Items.Add;
ListView1.Items[I].Caption := S + '\' + SearchRec.Name;
Inc(I);
if FileGetAttr(S + '\' + SearchRec.Name) = faDirectory then
GetFileDir(S + '\' + SearchRec.Name);
Found := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;begin
I := 0;
GetfileDir('C:');
end;我想把C盘里所以的目录和文件全部都加入在listview控件里面...可是为什么以上代码不行.. 还有一个问题就是listview里面可以加入多少条..有没有限制...
解决方案 »
- saveDBGridEhToExportFile导出excel问题
- delphi 可以登陆Discuz论坛 可是发帖就提示您的请求来路不正确
- 两个Pagecontrol之间能否使用splitter?
- 怎样在程序一运行,光标就在EDIT中
- 在dblookuplistbox中用locate方法得到的记录,如何显示记录被选中?
- 我用paradox7作为数据库编个小程序在没有delphi7.0的环境下怎么运行?(
- 提问 : 用IDftp控件怎么取得当前下载和上传的进度呢?
- 控件问题????
- 在delphi中調用sql server 的帶游標的存儲過程
- 错误为:Multiple records found,but only one was expected.怎么办???
- 如何在fastreport中显示金额的大写?
- 用delphi代码实现数据库的并发处理(急急急!)
2. 兄弟,为什么用I做临时变量,而不是定义一个TListItem对象?
3. SearchRec.Attr被浪费了,用FileGetAttr还不如用DirectoryExistsListView的条目在理论上没有什么限制,看你的机器了
http://lysee.oicp.net/downloads/lysee108_2232.exe
======================================================
function copyTree(const sourceDir, destiDir: string): boolean;
var
S, D: string;
begin
S := ExpandFileName(Trim(sourceDir));
Result := DirectoryExists(S);
if not Result then Exit; S := IncludeTrailingPathDelimiter(S);
D := includeTrailingPathDelimiter(ExpandFileName(Trim(destiDir)));
if sameFileName(S, D) then Exit; Result := copyFiles(S + '*.*', D, true);
end;function copyFiles(const fmask, destiDir: string; copyDir: boolean): boolean;
var
S, P, Path: string;
R: TSearchRec;
begin
Result := false; Path := ExpandFileName(Trim(destiDir));
if not DirectoryExists(Path) and not ForceDirectories(Path) then Exit;
Path := IncludeTrailingPathDelimiter(Path); S := ExpandFileName(Trim(fmask));
if SysUtils.FindFirst(S, faAnyFile, R) <> 0 then Exit;
try
P := ExtractFilePath(S);
Result := true;
repeat
if (R.Name <> '.') and (R.Name <> '..') then
begin
S := P + R.Name;
if (R.Attr and faDirectory) = 0 then
Result := CopyFile(PChar(S), PChar(Path + R.Name), false) else
if copyDir then
begin
S := IncludeTrailingPathDelimiter(S);
Result := copyFiles(S + '*.*', Path + R.Name, copyDir);
end;
end;
until not Result or (SysUtils.FindNext(R) <> 0);
finally
SysUtils.FindClose(R);
end;
end;function removeTree(const dir: string): boolean;
var
P: string; function rm_dir(const path: string): boolean;
var
R: TSearchRec;
begin
Result := true;
if SysUtils.FindFirst(path + '*.*', faAnyFile, R) = 0 then
try
repeat
if (R.Name <> '.') and (R.Name <> '..') then
if (R.Attr and faDirectory) = 0 then
Result := SysUtils.DeleteFile(path + R.Name) else
Result := rm_dir(IncludeTrailingPathDelimiter(path + R.Name));
until not Result or (SysUtils.FindNext(R) <> 0);
finally
SysUtils.FindClose(R);
end;
if Result then
Result := SysUtils.RemoveDir(ExcludeTrailingPathDelimiter(path));
end; function do_rmv_dir: boolean;
begin
Result := not DirectoryExists(P);
if not Result then
Result := rm_dir(IncludeTrailingPathDelimiter(P));
end;begin
P := ExpandFileName(Trim(dir));
Result := do_rmv_dir or do_rmv_dir;
end;