Results 1 to 4 of 4

Thread: Delete the contents of a directory using Batch

  1. #1
    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

  2. #2
    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

  3. #3
    Join Date
    Nov 2005
    Posts
    3,026

    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

  4. #4
    Join Date
    Apr 2008
    Posts
    3,267

    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

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,285,679.85794 seconds with 17 queries