例如:
硬盘有一目录M,其中有N个文件,N未知请问如何删除此目录和其中的所有文件???用那些函数???
我想遍历此目录,逐一删除目录中的文件,再删除目录名但如何实现???
要用到哪些函数???
硬盘有一目录M,其中有N个文件,N未知请问如何删除此目录和其中的所有文件???用那些函数???
我想遍历此目录,逐一删除目录中的文件,再删除目录名但如何实现???
要用到哪些函数???
解决方案 »
- 在FormCreate中关闭窗体
- spcom 在筆記本電腦上收不到數據,但在另一台試机上就行,不知何原因.已經困擾我一個星期了,請大家幫忙!
- 关于电脑连多台打印机Fastreport报“printer selected is not valid”错的问题
- 新建了一个查找字段,如何通过多个字段来返回要查找的字段值。
- 如何把一个SQL文件恢复为数据库
- 如何同时播放两个电影
- 求思路
- 各位大哥大姐,有在windows2008使用Delphi7 的吗?我安装完了delphi7打开,提示有错误呢,好像是某些文件load失败之类的,
- 请问:你们项目开发时,是用什么设计的?我是指设计(系统分析)
- 强烈抗议非本论坛内容的贴子进入!
- 有关DLL问题请高手指点
- 如何區分在Dephi里按F9運行還是直接運行程式??
var
hFindFile:Cardinal;
tfile:String;
sCurDir:String;
bEmptyDir:Boolean;
FindFileData:WIN32_FIND_DATA;
begin
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;
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; function DeleteDir(sDirName:String):Boolean;
begin
if Length(sDirName)< =0 then
exit;
Result:=DoRemoveDir(sDirName) and RemoveDir(sDirName);
end;
var
myrec:TSHFILEOPSTRUCT ;
begin
with myrec do
begin
Wnd:= Handle;
wFunc:= FO_DELETE;
pFrom:= nmm_strDir;
pTo:=nil;
fFlags:= FOF_NOCONFIRMATION or FOF_FILESONLY or FOF_SILENT;
fAnyOperationsAborted:= False;
hNameMappings:= nil;
lpszProgressTitle:= nil;
end;
if DirectoryExists(nmm_strDir) then
SHFileOperation(myrec);
end;