Re: Can't delete directories
- From: "Tom de Neef" <tdeneef@xxxxxxxx>
- Date: Thu, 28 Apr 2005 18:28:26 +0200
"DC." <jullape@xxxxxxxx> schreef in bericht
news:9ad1efc1.0504280723.995e5d@xxxxxxxxxxxxxxxxxxxxx
> Hi,
> I'm trying to delete the directories and files below a given
> directory, i have no problem deleting the files, but when i try to
> delete the directories, it complains, getlastError says that there
> could be any application using those directories. Is there any way to
> force those directories to be deleted?, the code is like follows:
>
> procedure DeleteAllFilesInDir(DirName:string);
> var
> DirInfo: TSearchRec;
> DirInfoDir: TSearchRec;
> r : Integer;
> begin
> r := FindFirst(DirName+'\*.*', FaAnyfile, DirInfo);
> while r = 0 do
> begin
> DeleteFile(pChar(DirName+'\' + DirInfo.Name));
> r := FindNext(DirInfo);
> end;
> SysUtils.FindClose(DirInfo);
>
> SetCurrentDir(Dirname);
> r := FindFirst('*', faDirectory, DirInfoDir);
> while r = 0 do begin
> if (DirInfoDir.name<>'.') and (DirInfoDir.name<>'..') then
> DeleteAllFilesInDir(pChar(DirName+'\' +
> DirInfoDir.Name));
> r := FindNext(DirInfoDir);
> end;
> if (not RemoveDir(dirname)) and (not m_avisado) then begin
> ShowMessageFmt('TestDir removed failure with error
> %d',[GetlastError]);
> m_avisado := true;
> end;
> SysUtils.FindClose(DirInfoDir);
> end;
>
> Thanks in advance.
And what happens when you remove the "SetCurrentDir(Dirname);" statement ?
Tom
.
- References:
- Can't delete directories
- From: DC.
- Can't delete directories
- Prev by Date: Can't delete directories
- Next by Date: ADOExpress and Service Applications
- Previous by thread: Can't delete directories
- Next by thread: Re: Can't delete directories
- Index(es):