下面代码为什么不能得到目录下的文件名字啊

lk2000 2003-11-26 03:31:34
function DelDirectory(const path: string): boolean; //删除目录
var
SearchRec: TSearchRec;
begin

if FindFirst(path , faAnyFile, SearchRec) = 0 then
begin

while FindNext(SearchRec) = 0 do
begin
showmessage(SearchRec.name);
end;
end;
...全文
33 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
午秋 2003-11-27
  • 打赏
  • 举报
回复
来自:xuzhsyf, 时间:2003-3-6 15:22:00, ID:1660494
删除目录的递归辅助函数:DoRemoveDir

function DoRemoveDir(sDirName:String):Boolean;
var
hFindFile:Cardinal;
tfile:String;
sCurDir:String;
bEmptyDir:Boolean;
FindFileData:WIN32_FIND_DATA;
begin
//如果删除的是空目录,则置bEmptyDir为True
//初始时,bEmptyDir为True
bEmptyDir:=True;
//先保存当前目录
sCurDir:=GetCurrentDir;
SetLength(sCurDir,Length(sCurDir));
ChDir(sDirName);
hFindFile:=FindFirstFile('*.*',FindFileData);
if hFindFile< >INVALID_HANDLE_VALUE then
begin
repeat
tfile:=FindFileData.cFileName;
if (tfile='.') or (tfile='..') then
begin
bEmptyDir:=bEmptyDir and True;
Continue;
end;
//不是空目录,置bEmptyDir为False
bEmptyDir:=False;
if FindFileData.dwFileAttributes=
FILE_ATTRIBUTE_DIRECTORY then
begin
if sDirName[Length(sDirName)]< >'\' then
DoRemoveDir(sDirName+'\'+tfile)
else
DoRemoveDir(sDirName+tfile);
if not RemoveDirectory(PChar(tfile)) then
result:=false
else
result:=true;
end
else
begin
if not DeleteFile(PChar(tfile)) then
result:=false
else
result:=true;
end;
until FindNextFile(hFindFile,FindFileData)=false;
FindClose(hFindFile);
end
else
begin
ChDir(sCurDir);
result:=false;
exit;
end;
//如果是空目录,则删除该空目录
if bEmptyDir then
begin
//返回上一级目录
ChDir('..');
//删除空目录
RemoveDirectory(PChar(sDirName));
end;

//回到原来的目录下
ChDir(sCurDir);
result:=true;
end;
删除目录的函数:DeleteDir

function DeleteDir(sDirName:String):Boolean;
begin
if Length(sDirName)< =0 then
exit;
//删除...
Result:=DoRemoveDir(sDirName) and RemoveDir(sDirName);
end;
hottey 2003-11-27
  • 打赏
  • 举报
回复
还有就是每个文件下都有 . 和.. 这两个东西..
要把它们干掉..
angelface 2003-11-26
  • 打赏
  • 举报
回复
我也想知道
确实是不行, 楼上的方法也不行
aiirii 2003-11-26
  • 打赏
  • 举报
回复
修改如下試試:
FindFirst(path + '\*.*' , faAnyFile, SearchRec)
lk2000 2003-11-26
  • 打赏
  • 举报
回复
RmDir能不能带文件删除路径?

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧