Solved

Delete directory and all subdirectory method

Posted on 2004-08-06
19
9,398 Views
Last Modified: 2013-12-27
Is there any command for deleting a directory and all subdirectories and/or files?

Or does anyone have a good script (*.cmd) file for doing this?
0
Comment
Question by:Axter
  • 8
  • 5
  • 4
  • +1
19 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 11739285
can't remember if you can doit...
but I think the Rexx tutorials used to include a sample code to do something like this.....

0
 
LVL 30

Author Comment

by:Axter
ID: 11741163
>>but I think the Rexx tutorials used to include a sample code to do something like this.....

I have no idea of what that is.
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 11742545
Rexx  is lnguage for basically writting command procedures , available on most IBM Operating systems...
I had a quicl look around but couldn't find what i wanted...
I'll try and look further.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11761628
Check for deltree command.

the syntax is

  deltree <path> /y /f

/y answers all questions with 'yes'
/f forces deltree to delete all files and sub directories

Regards, Alex
0
 
LVL 6

Expert Comment

by:Danny Kon
ID: 11767540
From site rob van der woude you can copy past this rexx util
Good luck
Dan


PARSE UPPER ARG user_dir confirm

IF STRIP(user_dir,'B') = '' THEN
      DO
             SAY 'You must enter a directory name to erase.'
             SAY 'To erase the current directory and all the ones below'
           SAY 'it, use a period (.).'
             EXIT 3
      END

/***********************************************************************/
/* Load the OS/2 RexxUtil DLL and make some functions available        */
/***********************************************************************/

CALL RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
CALL RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
CALL RxFuncAdd 'SysRmDir', 'RexxUtil', 'SysRmDir'

/***********************************************************************/
/* Load text strings for SysFileDel and SysRmDir return codes.         */
/***********************************************************************/

CALL LoadDELRCText   /* provides text strings for SysFileDel return codes */
CALL LoadRDRCText    /* provides text strings for SysRmDir return codes   */

/**************************************************************************/
/*Check to make sure the directory exists - if it does prompt the user to */
/*make sure they really want to do this.   Otherwise issue a message and  */
/*exit                                                            */
/**************************************************************************/

rc=SysFileTree(user_dir,dir_list, 'D')
IF dir_list.0 = 0  THEN
        DO
             SAY user_dir 'not found, try again.'
             EXIT 1
        END

DROP dir_list.

/***********************************************************/
/* Make sure the user really wants to do this              */
/***********************************************************/

IF confirm \= "/Y" THEN DO
      SAY 'Are you sure? (Y/N)'
      PULL answer .
      IF LEFT(answer,1,1) <> 'Y' THEN EXIT 1
END

/***********************************************************/
/* Mark all the read-only files to be non read-only        */
/***********************************************************/

rc=SysFileTree(user_dir, dir_list, 'BO', '****','----')

DROP dir_list.

/***********************************************************/
/* Go through the list of files and delete each one        */
/***********************************************************/

rc=SysFileTree(user_dir || '\*.*', dir_list, 'FSO')
DO x = 1 TO dir_list.0
      rc = SysFileDelete(dir_list.x)
      SAY dir_list.x '........' DELRCText.RC
END

DROP dir_list.

/*************************************************************/
/* Go through all the subdirectories and remove them.        */
/* We go backwards through the list in order to delete the   */
/* lowest level sudirectories first and work our way back up */
/* the tree.                                                 */
/*************************************************************/

rc=SysFileTree(user_dir || '\*.*', dir_list, 'DSO')
DO x = dir_list.0 TO 1 BY -1
      rc=SysRmDir(dir_list.x)
      SAY dir_list.x '........' RDRCText.RC
END

DROP dir_list.

/**************************************************************/
/* Delete the directory the user passed                    */
/**************************************************************/

rc=SysRmDir(user_dir)
SAY user_dir '........' RDRCText.RC

EXIT 0


/**************************************/
/* Local subroutines                  */
/**************************************/

LoadDELRCText:
      /* provides text strings for SysFileDel return codes */
      /* The return codes and strings are in the online Rexx manual */

      DELRCText.0 = 'File deleted successfully. '
      DELRCText.2 = 'Error.  File not found. '
      DELRCText.3 = 'Error.  Path not found. '
      DELRCText.5 = 'Error.  Access denied. '
      DELRCText.26 = 'Error.  Not DOS disk. '
      DELRCText.32 = 'Error.  Sharing violation. '
      DELRCText.36 = 'Error.  Sharing buffer exceeded. '
      DELRCText.87 = 'Error.  Invalid parameter. '
      DELRCText.206 = 'Error.  Filename exceeds range error. '
RETURN

LoadRDRCText:
      /* provides text strings for SysRmDir return codes */
      /* The return codes and strings are in the online Rexx manual */

      RDRCText.0 = 'Directory removal was successful. '
      RDRCText.2 = 'Error.  File not found. '
      RDRCText.3 = 'Error.  Path not found. '
      RDRCText.5 = 'Error.  Access denied. '
      RDRCText.16 = 'Error.  Current Directory. '
      RDRCText.26 = 'Error.  Not DOS disk. '
      RDRCText.87 = 'Error.  Invalid parameter. '
      RDRCText.108 = 'Error.  Drive locked. '
      RDRCText.206 = 'Error.  Filename exceeds range error. '
RETURN
0
 
LVL 30

Author Comment

by:Axter
ID: 11767556
itsmeandnobodyelse,

There is no deltree function.
At least not on my OS2 box.
0
 
LVL 30

Author Comment

by:Axter
ID: 11767582
dannykon,

Sorry dannykon, but I don't even know how I would use the above code, and I'm really interested in a method that would use *.CMD file or built-in OS function.
0
 
LVL 6

Expert Comment

by:Danny Kon
ID: 11767841
Axter,

Open an editor and copy past the above code, save the file as thenameyouwant.cmd

Good-Luck

Dan
0
 
LVL 6

Expert Comment

by:Danny Kon
ID: 11767963
Axter,

Before i forget

above the first line of code "PARSE UPPER ARG user_dir confirm" There have to be an indication for os/2 that this is a rexx file

So start the file with    /*   */  
after this you can paste the rest of the above code

/*   */  
PARSE UPPER ARG user_dir confirm

IF STRIP(user_dir,'B') = '' THEN
     DO

Etc etc etc

Good-Luck

Dan



0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11770137
I could send you a deltree.exe for OS/2 (11k 1994). Is  info ad axter dot com a valid  e mail address?

Regards, Alex

BTW, there is also a deltree.exe for Windows as

          del /s

doesn't work on W9x systems (as far i know).
0
 
LVL 30

Author Comment

by:Axter
ID: 11771353
>>I could send you a deltree.exe for OS/2 (11k 1994). Is  info ad axter dot com a valid  e mail address?

No.

I'm not sure if you can view the feedback, but I posted a valid email address in the feedback message.
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 250 total points
ID: 11776609
Finally, i found my feedback view ;-)

Did you get my mail?

Try deltree /? first. That is save. I tested it.

Regards, Alex
0
 
LVL 30

Author Comment

by:Axter
ID: 11780246
>>Did you get my mail?

Yes.   I'll try it out tomorrow when I get to work.

Did you get an email notificatiion when I posted the feedback?
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11780823
> Did you get an email notificatiion when I posted the feedback?

No, it's the first time i even recognized that possibility. I wonder if there is any kind of notification when receiving a feedback?

0
 
LVL 6

Assisted Solution

by:Danny Kon
Danny Kon earned 250 total points
ID: 11783818
Axter

Download the deltree command at location http://www.robvanderwoude.com/files/deldir.zip

Dan

0
 
LVL 30

Author Comment

by:Axter
ID: 11785114
>>No, it's the first time i even recognized that possibility. I wonder if there is any kind of
>>notification when receiving a feedback?

How were you able to view your feedback?

Now I'm woundering if I've ever got a feedback.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11785200
How were you able to view your feedback?

In "My Account" is a member feedback view...

You have 2 positive old feedbacks - same as me....

Regards, Alex
0
 
LVL 30

Author Comment

by:Axter
ID: 11785204
I just figured out how to view my feedback.
I only had 2, so I guess this feature doesn't get used too much.
0
 
LVL 30

Author Comment

by:Axter
ID: 11785247
Thank you both for your help.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Windows 7 does not have the best desktop search built in. This is something Windows 7 users have struggled with. You type something in, and your search results don’t always match what you are looking for, or it doesn’t actually work at all. There ar…
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

15 Experts available now in Live!

Get 1:1 Help Now