delete directory

  • Thread starter Thread starter adriana
  • Start date Start date
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
 
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.
 
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).
 
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.
 
Back
Top