delete files in command prompt

M

Matt

I want to delete all files under C:\temp, but C:\temp has many
subdirectories too.

I first go to C:\temp in command line, and del *.*, but it only deleted the
files, not files in the subdirectories. Also, it showed Are you sure (Y/N)?
question. How to disable the question and set default yes.

If I want to put this task in batch file, the following won't work at all.

cd C:/temp
del *.*

any ideas? thanks!!
 
P

Pegasus \(MVP\)

Matt said:
I want to delete all files under C:\temp, but C:\temp has many
subdirectories too.

I first go to C:\temp in command line, and del *.*, but it only deleted the
files, not files in the subdirectories. Also, it showed Are you sure (Y/N)?
question. How to disable the question and set default yes.

If I want to put this task in batch file, the following won't work at all.

cd C:/temp
del *.*

any ideas? thanks!!

To delete all folders in c:\temp:

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

To get around the "Y/N" prompt: Type del /? to
see all the switches available for the "del" command.
This is a standard help method for all Command Line
commands.
 
R

Rob Stow

Pegasus said:
To delete all folders in c:\temp:

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

Why not something much simpler like
rd /s /q c:\temp
md c:\temp
 
P

Pegasus \(MVP\)

Rob Stow said:
Why not something much simpler like
rd /s /q c:\temp
md c:\temp

Because the c:\temp folder might contain some files that
are locked by the operating system. Your version will
***probably*** work but it might bomb out on a locked
file error before the job is done.
 

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