Use the RemoveDir() procedure instead. Make sure it is not a current directory for your app, or any other too, or it will remain. SysUtils must be used to get the function.
If you need to, delete the contents of the directory first (below). Recursive deleting is possible, and consider the implications of the '.' test if you use directories or files with '.'.
procedure DeleteFiles( szDBDirectory : string );
var
szFile : string;
SearchRec: TSearchRec;
szSearchPath : string;
nResult : integer;
begin
szSearchPath := szDBDirectory;
nResult := FindFirst(szSearchPath + '\*.*', faAnyFile, SearchRec);
try
while 0 = nResult do
begin
if('.' <> SearchRec.Name[1]) then
begin
szFile := szSearchPath + '\' + SearchRec.Name;
{$IFDEF DEBUG_DELETE}
CodeSite.Send('Deleting "' + szFile + '"');
{$ENDIF}
FileSetAttr(szFile, 0);
DeleteFile(szFile);
end;
nResult := FindNext(SearchRec);
end;
finally
FindClose(SearchRec);
end;
end;