Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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
?
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
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.
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

721 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