Go Back   TechArena Community > Software > Operating Systems
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 11-09-2009
Member
 
Join Date: May 2009
Posts: 9
Delete the contents of a directory using Batch

Hello,

I am looking for the the dos command that can run in BATCH files in order to remove the entire contents of a directory (files + subdirectories) But this should delete the content only without deleting the directory in question because it is shared(temp, cookies, history). The command rmdir or rd does not solve my problem , please help me thanks in advance
Reply With Quote
  #2  
Old 11-09-2009
Member
 
Join Date: Nov 2005
Posts: 1,203
Re: Delete the contents of a directory using Batch

Personally, I use the batch file with the code below:

Code:
@ echo off 
echo Deleting Internet Explorer Cache 
del "%USERPROFILE%\Local Settings\Temporary Internet Files\*.*" /s /q 

echo Deleting History Internet Explorer 
del "%USERPROFILE%\Local Settings\History\*.* /s /q 

echo Deleting cookies in Internet Explorer 
del "%USERPROFILE%\ Cookies \ *.*" /s /q /f 

echo Deleting Data Application 
del "%USERPROFILE% Application Data \ *.*" /s /q /f 

echo Deleting files new opened 
del "%USERPROFILE%\ Recent \ *.*" /s /q /f 

echo Deleting files java 
del "%USERPROFILE%\.java \*.*" /s /q /f  

echo Deleting files java web start 
del "%USERPROFILE%\.javaws\*.*" /s /q /f 

echo Deleting files jpi_cache? 
del "%USERPROFILE%\.jpi_cache\*.*" /s /q /f 

echo Deleting the temporary directory 
del %TEMP% /s /q /f 

breaks
Reply With Quote
  #3  
Old 11-09-2009
Member
 
Join Date: Nov 2005
Posts: 3,023
Re: Delete the contents of a directory using Batch

The following batch deletes both subdirectories and files in D:\ASUP:

Code:

Code:
Select all for /f  "tokens=*" %%i in ('dir D:\ASUP\*.* /AD /B') do (RD "D:\ASUP\%%i" /S /Q) 
echo o | del D:\ASUP\*.*

Be careful while using it
Reply With Quote
  #4  
Old 11-09-2009
Member
 
Join Date: Apr 2008
Posts: 3,260
Re: Delete the contents of a directory using Batch

Code:
CD "path\to\cookies"
DEL *.*
CD\
First line will get you *inside* the folder Second line will delete everything in there Third line will then get you back to the root of your drive
Reply With Quote
Reply

  TechArena Community > Software > Operating Systems
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Delete the contents of a directory using Batch"
Thread Thread Starter Forum Replies Last Post
How can I delete folders without it's contents venkat=raghavan Windows Software 3 18-10-2010 02:15 PM
Batch script to delete directory Logan 2 Software Development 4 01-04-2010 12:31 PM
Batch file to check directory Trini Alvarado Software Development 5 01-04-2010 11:00 AM
Virtual Directory does not allow contents to be listed Sachit Networking & Security 3 11-07-2009 09:54 AM
Show directory contents in C Janet J Software Development 2 05-02-2009 11:43 PM


All times are GMT +5.5. The time now is 09:11 PM.