Batch Delete Help

J

jeffbg123

I am trying to find a batch command that takes a directory and deletes
all files in that directory, along with subdirectories, leaving an
empty top level folder.

For instance I have a directory C:\test. In C:\test there are 5 .txt
files and another directory called C:\test\t2. In C:\test\t2 there are
7 mp3 files. I want a command that will delete all of the txt files,
all of the mp3 files, and the t2 folder, leaving C:\test with no files
and no subdirectories.

Any ideas?

Thanks

-Jeff
 
P

Pegasus

jeffbg123 said:
I am trying to find a batch command that takes a directory and deletes
all files in that directory, along with subdirectories, leaving an
empty top level folder.

For instance I have a directory C:\test. In C:\test there are 5 .txt
files and another directory called C:\test\t2. In C:\test\t2 there are
7 mp3 files. I want a command that will delete all of the txt files,
all of the mp3 files, and the t2 folder, leaving C:\test with no files
and no subdirectories.

Any ideas?

Thanks

-Jeff

Here are a couple of methods:

@echo off
rd /s /q c:\Test
md c:\Test

@echo off
for /d %%a in (c:\Test\*.*) do rd /s /q "%%a"
del /q c:\Test\*.*
 
J

jeffbg123

Thanks. Is there any way to do it without having to enter the
directory in more than once?
 
P

Pegasus

Why would it matter in a batch file?

You can, of couse, set an intial variable, then refer to
to it on all subsequent occasions, e.g. like so:

@echo off
set name=Jeff
echo My name is %name%
 
J

jeffbg123

I am trying to make a quick way to clear the cache of dreamweaver. The
most effective way seems to delete the contents of the cache
directories. There are about 10 directories to delete and I have to do
this on about 6 different computers, each having different
directories. So I want to setup a template that I can modify.

Something like this does not seem to work:

@echo off
set direc = "C:\test\"

RD /S /Q %direc%
MD %direc%

What did I do wrong?
 
P

Pegasus

I can't tell what's wrong with your batch file unless you post
the error message(s) you see.

In your situation a better method might go like this:

@echo off
echo.
set /p folder=Please enter the folder to be deleted:
if "%folder%"=="" goto :eof
echo Clearing "%folder%" . . .
rd /s /q "%folder%"
md "%folder%"
echo Done! Press the space bar to close this window.
pause > nul
 

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