Solved

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

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Script to write to a log file 18 47
Windows 2008 set profile 9 49
Remote start and stop of service 3 47
if then inside for loop not working - Batch scripting 8 29
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

696 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