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

I am looking for a SHORT batch file in XP or 2003 to delete ALL files AND folders in a specified directory.
Who is Participating?
PaulKeatingConnect With a Mentor Commented:
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"

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
	  ' Check for subfolders
	  for each objFolder in objFSO.GetFolder(strFolders(i)).Folders
	    objFolder.Delete true
	end if

Open in new window

tru504187211Author Commented:
That's exactly the one liner that I need!  THANK!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.