Hi,
I'm trying to delete a directory if it exists.
it works if the directory is empty, but if I put a file in there it fails.
The code below is correctly finding the file (I put a showmessage in there to prove it to myself) but the DeleteFile seems to do nothing.
What is wrong with my method?
I'm trying to delete a directory if it exists.
it works if the directory is empty, but if I put a file in there it fails.
The code below is correctly finding the file (I put a showmessage in there to prove it to myself) but the DeleteFile seems to do nothing.
What is wrong with my method?
Code:
if DirectoryExists(Dest) then
begin
if FindFirst(Dest + '*.*', faAnyFile, SR) = 0 then
begin
repeat
if (SR.Attr And faDirectory) <> faDirectory then
begin
SysUtils.DeleteFile(SR.Name);
end;
until FindNext(SR) <> 0;
FindClose(SR);
end;
RemoveDir(Dest);
end;