Delete empty directory problem
Posted on 2003-03-02
Im using following two procedure/function to check if a directory is empty and to delete the empty directory.
But im getting an error message that the directory is in use by a program and can not be deleted. WHY?
I suspect that its my program that have the rights and stops the "delete", how to get around this ?
function IsDirEmpty (const ADirPath :string) :boolean;
var F :TSearchRec;
result := (FindFirst(ADirPath+'\*.*',faAnyFile,F) = 0) and
(FindNext(F) = 0) and
(FindNext(F) <> 0);
function DeleteFolder(FolderName: String; LeaveFolder: Boolean): Boolean;
Result := False;
if not DirectoryExists(FolderName) then
if LeaveFolder then
FolderName := FolderName + ' *.* '
if FolderName[Length(FolderName)] = ' \ ' then
FillChar(r, SizeOf(r), 0);
r.wFunc := FO_DELETE;
r.pFrom := PChar(FolderName);
r.fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION; // or FOF_SILENT
Result := ((ShFileOperation(r) = 0) and (not r.fAnyOperationsAborted));