X3平台版本:2827
代码如下:
procedure MForm.Button4Click(Sender: TObject);
var
SHFILEOPSTRUCTA : _SHFILEOPSTRUCTA;
lPath : string;
begin
lPath := edtDir.Text.Trim;
if lPath = '' then
exit;
// 处理最后的 '\'
if lPath.Substring(lPath.Length-1,1) <> '\' then
lPath := lPath + '\';
if not SysUtils.DirectoryExists(lPath+'test\') then
begin
if not Business.System.SysUtils.CreateDir(lPath+'test\') then
begin
Business.Forms.Dialogs.ShowMessage('创建目录失败,终止!');
exit;
end;
end
else
begin
SHFILEOPSTRUCTA.Wnd := 0;
SHFILEOPSTRUCTA.wFunc := FO_DELETE;
SHFILEOPSTRUCTA.pFrom := lPath+'test';
//SHFILEOPSTRUCTA.pTo := lPath+'test';
SHFILEOPSTRUCTA.fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR+FOF_NOERRORUI;
SHFILEOPSTRUCTA.fAnyOperationsAborted := false;
SHFILEOPSTRUCTA.hNameMappings := nil;
SHFILEOPSTRUCTA.lpszProgressTitle := '正在删除文件夹...';
if SHFileOperation(SHFILEOPSTRUCTA) = 0 then
begin
if not Business.System.SysUtils.CreateDir(lPath+'test\') then
begin
Business.Forms.Dialogs.ShowMessage('创建目录失败,终止!');
exit;
end;
end
else
begin
Business.Forms.Dialogs.ShowMessage('删除目录失败,终止!');
exit;
end;
end;
end;
目录肯定存在,目录内无论是否有内容都删除不成功 |