Solved

Removing files and subdirectories

Posted on 1997-04-06
1
260 Views
Last Modified: 2010-04-06
I try to remove files and subdirectories within a directory.
I've tried to recurse the subdirs and remove the files. It works, except that it won't delete the subdirs.
I've also tried to remove it by WinExec ('rm l:\dd\ /s',0); but that just removes everything on L: except that sub.
Is there a way to solve this?
Thanx for all help.
0
Comment
Question by:bear040497
1 Comment
 
LVL 3

Accepted Solution

by:
mheacock earned 50 total points
ID: 1335216
DelTree('C:\JUNK\'); //  Remember the ending backslash

Function DelTree(S: String): Boolean;
Var
  SR       : TSearchRec;
  ErrCode  : LongInt;
  PC       : PChar;

  Begin
    ErrCode :=  FindFirst(S+'*.*', faAnyFile, SR);
    While ErrCode = 0 do
      Begin

         If Not ((SR.Name = '.') or (SR.name = '..')) then
           Begin
             If (SR.Attr and faDirectory) = faDirectory  then
               Begin
                 DelTree(S+SR.Name+'\');
                 RMDir(S+Sr.Name);
                 IOResult;
               End
              Else
               Begin
                 PC := StrAlloc( Max_Path );
                 StrPCopy(PC, S+SR.Name);
                 SetFileAttributes(PC, FILE_ATTRIBUTE_NORMAL);
                 DeleteFile(PC);
                 StrDispose(PC);
                End;
           End;

        ErrCode := FindNext(SR);
      End;
     Result := False;
     If (ErrCode = 0) or (ErrCode = 18) then Result := True;
  End;


0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 166
Delphi : could not find program, '...exe' 2 191
Magic Software info 18 138
PHP preg_replace code convert to Delphi 14 66
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question