Solved

Removing files and subdirectories

Posted on 1997-04-06
1
255 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 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