delete directory

A

adriana

Hi,

How can I delete aLL directory from un specified
directory but not itself.

Thanks
 
R

Ray at

Set theDir=C:\dir
RD /S %theDir%
MD %theDir%

That's one way, if you don't have any permissions set or anything else to
worry about. It'll delete the dir (taking all contents with it) and then
create a new dir with the same name.

Ray at work
 
M

Matthias Tacke

Dean Wells said:
CD <directory name>
RD /s /q .
In case your current directory is on a different drive this could end up
in a disaster ;-)
I would include /D

CD /D <directory name>
RD /s /q .

Otherwise I prefer this approach since creation date of the folder is
preserved.
 
P

Phil Robyn

Matthias said:
In case your current directory is on a different drive this could end up
in a disaster ;-)
I would include /D

CD /D <directory name>
RD /s /q .

Otherwise I prefer this approach since creation date of the folder is
preserved.

Or else use 'PUSHD <drive:\directoryname>' instead of 'CD /D <drive:\directoryname>'
(then you can use 'POPD' to return to where you started from).
 
D

Dean Wells [MVP]

Matthias said:
In case your current directory is on a different drive this could end
up in a disaster ;-)
I would include /D

CD /D <directory name>
RD /s /q .

Otherwise I prefer this approach since creation date of the folder is
preserved.

Great addition and well worth pointing out.
 

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