English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I need a simple batch file to work on XP that will go into a specific directory and delete all files and sub folders (including non empty directories).

Below is what I had and I thought it worked, but it deletes the root folder too. I need to keep the initial folder and delete everything else.

@ECHO OFF
rmdir "C:\test" /s

echo C:\test has been deleted successfully
echo Please inform the ISD technician that the system is ready

pause

Secondly, is there a way to make it NOT prompt for y or n on deletions? The less intervention of our endusers, the better.

2007-10-25 04:31:46 · 5 answers · asked by biggestperlnerd 3 in Computers & Internet Programming & Design

5 answers

There's a couple ways to approach this.

Option #1) The easiest way.
If you just want a fresh, empty "c:\test" directory, then you could simply delete the whole thing, then create a new directory. You were on the right track for this ... just needed the "/q" for quiet deletion, and recreate your test directory.


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

echo C:\test has been deleted successfully
echo Please inform the ISD technician that the system is ready
================


Option #2) A little more complex.
You can parse the files and folders in the c:\test directory and delete them from the root.


@echo off
rem delete files quietly from the root of c:\test.
del c:\test\. /f /q

rem delete all sub-dirs quietly from the root of c:\test
for /f "tokens=*" %i in ('dir test /b') do rd "%i" /s /q

echo C:\test has been deleted successfully
echo Please inform the ISD technician that the system is ready

==============
Couple of other notes on other suggestions,

Deltree - no longer native in Windows 2000 or Windows XP. Retired with NT/95.

Doing del c:\test\*.* /(whatever the switch is), plus the switch for not prompting,
Which would look like,

del c:\test\*.* /s /q

Would delete all non-readonly files, but not sub-directories. You'd be left with whatever directory tree structure you had under c:\test, plus any read-only files that might be there.

==============

I'd go for option #1, personally.

==============

2007-10-25 13:23:52 · answer #1 · answered by Kevin 7 · 3 0

Batch Delete Folder

2016-10-18 00:11:14 · answer #2 · answered by ? 4 · 0 0

Delete Non Empty Directory

2016-12-26 10:33:38 · answer #3 · answered by donnellan 4 · 0 0

I'm not entirely sure in windows but in DOS I would try "DELTREE /y" to delete the entire directory with out fighting the "y/n prompt" issue and then add a "MKDIR DirectoryName" command in the BAT file.

2007-10-25 06:00:30 · answer #4 · answered by DynaSoar 4 · 0 0

Check to options to del, I don't have a Windows machine here to check, but if you type del /? from a command prompt, I think there is a switch to make it do a recursive delete. Then use :
del c:\test\*.* /(whatever the switch is), plus the switch for not prompting. Use with care.

2007-10-25 04:50:01 · answer #5 · answered by Anonymous · 0 0

fedest.com, questions and answers