Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-25
4
Medium Priority
?
265 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Integration Management Part 2
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

877 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