?
Solved

Removing files and subdirectories

Posted on 1997-04-06
1
Medium Priority
?
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
mheacock earned 100 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

762 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