Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delete directory and all subdirectory method

Posted on 2004-08-06
19
Medium Priority
?
9,415 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
[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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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 1000 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Occasionally Windows/Microsoft Updates will fail to update. We have found a code that will delete all temporary files and re-register all dll's related to Windows/Microsoft Updates! This works 99% of the time to get the updates working again! The…
Just about everyone has an old PC laying around.  Ask anyone in the IT industry, whether they are a professional or play in it as a hobby.  From outdated Desktops to cheap "throwaway" laptops, they are all around and not as hard to "fix up" as you m…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

650 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