Solved

Removing files and subdirectories

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now