[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Removing files and subdirectories

Posted on 1997-04-06
1
Medium Priority
?
276 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 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

834 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