LucieLastic
Programmer
hi All
I'd like to completely empty a directory and was wondering if there's a quick and easy solution. I tried the following but it access violates on the SHFileOperation:-
procedure TFormMain.DeleteFilesInDir;
var FileOpInfo : TSHFileOpStruct;
begin
with FileOpInfo do
begin
wnd := self.Handle;
wFunc := FO_DELETE;
if edCsvDirAct.Caption[length(edCsvDirAct.Caption)] <> '\' then
edCsvDirAct.Caption := edCsvDirAct.Caption +'\';
pFrom := pChar(edCsvDirAct.Caption+'*.*');
fFlags := FOF_FILESONLY;//FOF_ALLOWUNDO;
end;
SHFileOperation(FileOpInfo);
SHFreeNameMappings(GlobalHandle(FileOpInfo.hNameMappings));
end;
A straight delete of the directory would be good but RemoveDirectory needs an empty dir.
Will I have to do it with a FindFirst and DeleteFile? Was hoping for a more subtle solution...
lou
I'd like to completely empty a directory and was wondering if there's a quick and easy solution. I tried the following but it access violates on the SHFileOperation:-
procedure TFormMain.DeleteFilesInDir;
var FileOpInfo : TSHFileOpStruct;
begin
with FileOpInfo do
begin
wnd := self.Handle;
wFunc := FO_DELETE;
if edCsvDirAct.Caption[length(edCsvDirAct.Caption)] <> '\' then
edCsvDirAct.Caption := edCsvDirAct.Caption +'\';
pFrom := pChar(edCsvDirAct.Caption+'*.*');
fFlags := FOF_FILESONLY;//FOF_ALLOWUNDO;
end;
SHFileOperation(FileOpInfo);
SHFreeNameMappings(GlobalHandle(FileOpInfo.hNameMappings));
end;
A straight delete of the directory would be good but RemoveDirectory needs an empty dir.
Will I have to do it with a FindFirst and DeleteFile? Was hoping for a more subtle solution...
lou