delphi delete the entire file and directory directory

Original link: http://www.cnblogs.com/yzryc/p/deldir.html

// delete the entire folder and all its files
function DelDirAll (ADIR: String): Boolean;
var
vSearch: TSearchRec;
Vret: Integer;
vKey: String;
the begin

if aDir[Length(aDir)] <> '\' then
aDir := aDir + '\';
vKey := aDir + '*.*';
vRet := FindFirst(vKey, faanyfile, vSearch);
while vRet = 0 do
begin
if ((vSearch.Attr and fadirectory) = fadirectory) then
begin
if (vSearch.Name <> '.') and (vSearch.name <> '..') then
DelDirAll(aDir + vSearch.name);
end
else
begin
if ((vSearch.Attr and fadirectory) <> fadirectory) then
begin
{System.Sysutils.}DeleteFile(aDir + vSearch.name);
end;
end;
vRet := FindNext(vSearch);
end; //while

{.} System.SysUtils FindClose (vSearch);
RemoveDir (ADIR); // If you need to delete a folder you added
the Result: = True;
End;

 

///////////////////

 

var
P: Integer;
P1, P2: PChar;
IconIndex: Word; // The icon in the Position of File The
FileName: TFileName ;
the begin
IconIndex: = 0;
FileName: = 'D: \ Yang \ Projects \ Lo is \ Fuzhou Daily extranet publishing tools \ data distribution and backup tools \ Win32 \ Debug \ data distribution and backup tool .exe, 1 ';
p1: = PChar (FileName);
P2: = StrRScan (p1,', '); // characters from Find single string leftmost character
IF P2 <> nil the then the begin
P: = P2 - P1 +. 1; // The comma the Position of
the try
IconIndex: = StrToInt (the Copy (FileName, P +. 1, the Length (FileName) - P ));
ShowMessage (IntToStr (IconIndex));
the except
ON E: EConvertError do
the begin
ShowMessage (e.Message);
End;
End;
SetLength(FileName, p - 1);
end;
end;

Reproduced in: https: //www.cnblogs.com/yzryc/p/deldir.html

Guess you like

Origin blog.csdn.net/weixin_30919429/article/details/94795436