DELTREE equivalent

A

Andrew Aronoff

I'm looking for a replacement for DELTREE.EXE under W2K. I've read in
various Usenet posts that RD and/or DEL can be used, but I haven't
found this to be true in my tests.

I'm looking for a command to replace the following:

DELTREE /Y C:\TEMP\

This single command deletes the entire contents of the directory
C:\TEMP (including subdirectories and their contents) _without_
deleting the directory itself.

RD /Q /S C:\TEMP deletes the TEMP directory, too.

Is there a closer fit? (If not, I'll stick with DELTREE, which works
perfectly well in a CMD.EXE shell under W2K and WXP.)

regards, Andy
--
**********

Please send e-mail to: usenet (dot) post (at) aaronoff (dot) com

To identify everything that starts up with Windows, download
"Silent Runners.vbs" at www.silentrunners.org

**********
 
M

Mark V

In said:
I'm looking for a replacement for DELTREE.EXE under W2K. I've
read in various Usenet posts that RD and/or DEL can be used, but
I haven't found this to be true in my tests.

I'm looking for a command to replace the following:

DELTREE /Y C:\TEMP\

This single command deletes the entire contents of the directory
C:\TEMP (including subdirectories and their contents) _without_
deleting the directory itself.

RD /Q /S C:\TEMP deletes the TEMP directory, too.

Run that from *within* the c:\temp\ location.
 
R

R Harrison

You could scrip it so that you do the RD function, which will delete the
entire structure as you mentioned, then do an MD Temp to recreate it again.

The only way to remove all directories in C:\Temp is to RD them 1 at a time,
because RD does remove the root directory in the command.

Suggested bacth file
*************************
c:
cd\
RD /S /Q C:\Temp
md temp
*************************
 
M

Mark V

In said:
You could scrip it so that you do the RD function, which will
delete the entire structure as you mentioned, then do an MD Temp
to recreate it again.

The only way to remove all directories in C:\Temp is to RD them
1 at a time, because RD does remove the root directory in the
command.

Not if you are "in" it.
 
B

billious

Andrew Aronoff said:
I'm looking for a replacement for DELTREE.EXE under W2K. I've read in
various Usenet posts that RD and/or DEL can be used, but I haven't
found this to be true in my tests.

I'm looking for a command to replace the following:

DELTREE /Y C:\TEMP\

This single command deletes the entire contents of the directory
C:\TEMP (including subdirectories and their contents) _without_
deleting the directory itself.

RD /Q /S C:\TEMP deletes the TEMP directory, too.

Is there a closer fit? (If not, I'll stick with DELTREE, which works
perfectly well in a CMD.EXE shell under W2K and WXP.)

regards, Andy
--


How about (as a batch file, obviously)

xcopy /t /e c:\temp c:\somejunkname\
rd /q/s c:\temp
ren c:\somejunkname temp

You could possibly build somejunkname (just in case somejunkname might
already exist) using something like

set yjn=x
:loop
if exist c:\%yjn%* set yjn=%yjn%q&goto loop

which should set %yjn% (Your Junk Name) to "x" followed by as many "q"s as
are required to make the string unique. use %yjn% in place of somejunkname
in the above, clean up yjn using

set yjn=

to remove yjn from the environment, and job done.

HTH

....Bill
 
A

Andrew Aronoff

RD /Q /S C:\TEMP deletes the TEMP directory, too.
Run that from *within* the c:\temp\ location.

Thanks. Didn't know that. That's certainly a very close fit.

regards, Andy
--
**********

Please send e-mail to: usenet (dot) post (at) aaronoff (dot) com

To identify everything that starts up with Windows, download
"Silent Runners.vbs" at www.silentrunners.org

**********
 
A

Andrew Aronoff

RD /Q /S C:\TEMP deletes the TEMP directory, too.
Run that from *within* the c:\temp\ location.

Oops! I tried it out and it does what's needed, but it throws the
error, "The process cannot access the file because it is being used by
another process." Do you know of any way around that?

regards, Andy
--
**********

Please send e-mail to: usenet (dot) post (at) aaronoff (dot) com

To identify everything that starts up with Windows, download
"Silent Runners.vbs" at www.silentrunners.org

**********
 
A

Andrew Aronoff

How about (as a batch file, obviously)
xcopy /t /e c:\temp c:\somejunkname\
rd /q/s c:\temp
ren c:\somejunkname temp

Thanks for the suggestion. I think the /e parameter is best omitted
since it copies the subdirectories, which DELTREE would have deleted.

IAC, I think I'll stick with DELTREE, which is simpler to deploy and
run.

regards, Andy
--
**********

Please send e-mail to: usenet (dot) post (at) aaronoff (dot) com

To identify everything that starts up with Windows, download
"Silent Runners.vbs" at www.silentrunners.org

**********
 
B

Bill Stewart

Andrew said:
Oops! I tried it out and it does what's needed, but it throws the
error, "The process cannot access the file because it is being used by
another process." Do you know of any way around that?

Yes. Redirect STDERR to NUL. Sample script fragment:

pushd %1 || goto :EOF
rd /q /s . 2> NUL
popd
 
A

Andrew Aronoff

Oops! I tried it out and it does what's needed, but it throws the
Yes. Redirect STDERR to NUL. Sample script fragment:

pushd %1 || goto :EOF
rd /q /s . 2> NUL
popd

Sorry, I wasn't clear. I wanted to know how to avoid the error, not
suppress the display.

regards, Andy
--
**********

Please send e-mail to: usenet (dot) post (at) aaronoff (dot) com

To identify everything that starts up with Windows, download
"Silent Runners.vbs" at www.silentrunners.org

**********
 
M

Mark V

In said:
Sorry, I wasn't clear. I wanted to know how to avoid the error,
not suppress the display.

This "error" is part of the "but don't remove the target directory
itself" and for this purpose is entirely innocuous and expected.

I'd be careful with DELTREE since it is not supplied with W2K. It
may fail under conditions found but for which it is was not
designed.

RMDIR is "native". Enhance your batch usage by confirming the CD
after you have changed into the target and before issuing
RD /s /q .

And for anyone trying to justify a method of just removing the
target tree and then recreating the top-level directory, methinks
you are not taking security into account (NTFS ACLs).
 
A

Andrew Aronoff

Thanks for your patient explanation.
This "error" is part of the "but don't remove the target directory
itself" and for this purpose is entirely innocuous and expected.

Then that means there is no true drop-in for DELTREE under W2K. That's
what I wanted to know.
I'd be careful with DELTREE since it is not supplied with W2K.

IMHO, that's not suffiicient reason to avoid it.
It may fail under conditions found but for which it is was not
designed.

Hasn't yet. (I've been using it on multiple systems for years.)
RMDIR is "native".

.... and DELTREE "works".
Enhance your batch usage by confirming the CD
after you have changed into the target and before issuing
RD /s /q .

I've got an even better idea. I'll keep using DELTREE. ;-)

Thanks again.

regards, Andy
--
**********

Please send e-mail to: usenet (dot) post (at) aaronoff (dot) com

To identify everything that starts up with Windows, download
"Silent Runners.vbs" at www.silentrunners.org

**********
 
M

Mark V

In said:
Thanks for your patient explanation.


Then that means there is no true drop-in for DELTREE under W2K.
That's what I wanted to know.

Correct. Nothing exactly equivalent is provided. But there are
likely 3rd-party "deltrees" written for NTx available.
IMHO, that's not suffiicient reason to avoid it.

Good luck.
Hasn't yet. (I've been using it on multiple systems for years.)


... and DELTREE "works".

As you like.
 
F

foxidrive

Thanks for your patient explanation.


Then that means there is no true drop-in for DELTREE under W2K. That's
what I wanted to know.

Here ya go - better test it well.

@echo off
:: deltree.cmd
if [%1]==[] echo How about a folder, jerk!&goto :EOF
for /f "delims=" %%a in ('dir %1 /a:d /b') do rd /q /s %1\"%%a"
del /q %1\*.*
 
J

Jerold Schulman

I'm looking for a replacement for DELTREE.EXE under W2K. I've read in
various Usenet posts that RD and/or DEL can be used, but I haven't
found this to be true in my tests.

I'm looking for a command to replace the following:

DELTREE /Y C:\TEMP\

This single command deletes the entire contents of the directory
C:\TEMP (including subdirectories and their contents) _without_
deleting the directory itself.

RD /Q /S C:\TEMP deletes the TEMP directory, too.

Is there a closer fit? (If not, I'll stick with DELTREE, which works
perfectly well in a CMD.EXE shell under W2K and WXP.)

regards, Andy


See tip 0617 » How do I remove all files and sub-directories from a folder, without removing the folder?
in the 'Tips & Tricks' at http://www.jsifaq.com


Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top