Solved

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

Posted on 2008-10-25
4
258 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

932 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

10 Experts available now in Live!

Get 1:1 Help Now