Solved

Batch file in XP or 2003 to delete ALL files AND folders in a specified directory

Posted on 2008-10-25
4
257 Views
Last Modified: 2012-05-05
I am looking for a SHORT batch file in XP or 2003 to delete ALL files AND folders in a specified directory.
0
Comment
Question by:tru504187211
4 Comments
 
LVL 7

Expert Comment

by:Raymond Jansen
ID: 22804797
0
 
LVL 5

Accepted Solution

by:
PaulKeating earned 500 total points
ID: 22805031
I may have missed the point of the question, but if you just want a batch file to delete a directory subtree then this is that batch file:

rmdir /s /q "%~1"

Save it as (say) deletesubtree.cmd and invoke it as follows

deletesubtree "C:\my unwanted folder\data files"




0
 
LVL 70

Expert Comment

by:KCTS
ID: 22805058
You can use a vbscript - this one was given to me by PurplePomegranite


dim strFolders

dim i

dim objFSO

dim objFile

dim objFolder

 

strFolders=array("c:\temp","c:\temp2") ' List all folders to be cleared here
 

  on error resume next ' Ignore any errors

  set objFSO=CreateObject("Scripting.FileSystemObject")

  for i=0 to UBound(strFolders)

    if objFSO.FolderExists(strFolders(i)) then

	  ' Folder exists, so delete it's contents

	  for each objFile in objFSO.GetFolder(strFolders(i))

		objFile.Delete true

	  next

	  ' Check for subfolders

	  for each objFolder in objFSO.GetFolder(strFolders(i)).Folders

	    objFolder.Delete true

	  next

	end if

  next

Open in new window

0
 

Author Closing Comment

by:tru504187211
ID: 31509994
That's exactly the one liner that I need!  THANK!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now