Results 1 to 10 of 10

Thread: Create a batch (. Bat) MS-DOS to delete files

  1. #1
    Join Date
    Nov 2008
    Posts
    98

    Create a batch (. Bat) MS-DOS to delete files

    Hello , I might need some tips for MS DOS. I would like to create a file in ms dos bat for me to delete my chat histories, empty my trash, etc If someone could help me, I could not find the way to do it please suggest proper replies thanks

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Create a batch (. Bat) MS-DOS to delete files

    If you want to delete a directory you must add / s at the command DEL to delete a folder, but if you're wrong place and you put *.* it will delete files ... I gave you and idea but I am not responsible for your deletions.

    Example syntax to delete the folder TMP

    DEL C: \ TMP / Q / S

    type this in notepad and save it batch (having extension .bat) and then executes the file to see the effect

  3. #3
    Join Date
    May 2008
    Posts
    115

    Re: Create a batch (. Bat) MS-DOS to delete files

    Make a new text file and rename it to _____.bat (fill in the blank with a name of your choice). I'm assuming you know how to change file name extensions.

    Right click on the .bat file. Choose 'edit'.


    type this:


    del " x \*._y_"


    fill in blank x with the directory name

    fill in blank y with the extension of the file type you want to delete or '*' for all files.


    EXAMPLE

    del "C:\New Folder\*.*" - this will delete everything in the folder

    OR

    del "C:\Another Folder\*.jpg" - this will only delete files with the jpg extension

    Now you can save the batch file and run it.

  4. #4
    Join Date
    Nov 2008
    Posts
    98

    Re: Create a batch (. Bat) MS-DOS to delete files

    Thank you, it works perfectly, with a particular directory.

    Now my problem is complicated because the directory name change to delete every day ....
    Example today: S103_01 then S104_01, S105_01 .... I tried your formula but with S * for a directory that is denied!

    In fact there is an initial directory C: \ backup01 , which receives a daily backup directory S103_01, then the next day S104_01 etc ..., each of these directories contain the backup files. Eventually there is a stack of these directories S. .. _01, which is unnecessary and I would like to clear a routine automatically whenever you start the computer. This does not seem very logical to delete backups, but every day is redirected to other media from their creations.

    Thank you.

  5. #5
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Create a batch (. Bat) MS-DOS to delete files


  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Create a batch (. Bat) MS-DOS to delete files

    Try it- it should resolve your concerns Long live DOS:

    C:
    CD \ backup01
    for / d% i in (s *.*) DO del% i / Q / S
    for / d% i in (s *.*) DO rd% i

    (If you put this command in a BAT file you must use%% i in place of% i must be doubled in the file% BAT).

  7. #7
    Join Date
    Sep 2011
    Posts
    3

    Re: Create a batch (. Bat) MS-DOS to delete files

    Hi

    try it- it should resolve your concerns Long live DOS:

    C:
    CD \ backup01
    for / d% i in (s *.*) DO del% i / Q / S
    for / d% i in (s *.*) DO rd% i

    (If you put this command in a BAT file you must use%% i in place of% i must be doubled in the file% BAT).
    I am trying to delete everything(files,directories , sub directories...etc) inside current directory , i have tried the above commands but it fails , here is the the code


    Code:
    D:\test>for / d% i in (s *.*) DO del% i / Q / S
    / was unexpected at this time.
    
    D:\test>for / d% i in (s *.*) DO rd% i
    / was unexpected at this time.
    
    D:\test>
    BTW I am using XP but I want to apply that to XP , Vista , Win 7
    Last edited by techbrainless; 05-09-2011 at 02:40 AM.

  8. #8
    Join Date
    Jan 2006
    Posts
    605

    Re: Create a batch (. Bat) MS-DOS to delete files

    Follow the below steps to delete all files an directories:

    del c:\[directory you want to delete] /s

    Just create this in a new text file that should be created in notepad, and saved as a .bat file. Or you could type EDIT from the command line to bring up the old DOS editor.

    Step 1: Open up Notepad

    Step 2: Type the following code in:

    @echo off

    deltree [Your hard drive, usually C:]\[Directory you want to delete /s for quietly

    Step 3: Save as "whateveryouwantwithoutquotes.bat"

  9. #9
    Join Date
    Sep 2011
    Posts
    3

    Re: Create a batch (. Bat) MS-DOS to delete files

    Thanks Janos for your reply ,

    deltree [Your hard drive, usually C:]\[Directory you want to delete /s for quietly
    I am sure that you have not read my question in the previous reply post


    I am trying to delete everything(files,directories , sub directories...etc) inside current directory

    Let us assume that we have placed the .batch file at the location "D:\test\mybatch.bat"

    once you have browsed to the directory "test" , double clicking on the batch file "mybatch.bat" , it should delete all the contents of the directory "test" ("D:\test")
    off course the batch file should delete all the contents of "test" directory except itself "mybatch.bat"

  10. #10
    Join Date
    Sep 2011
    Posts
    3

    Re: Create a batch (. Bat) MS-DOS to delete files

    Hi All ,

    Here is the batch file which works delete all the content of directory except the batch file (BUT BE CAREFUL , TEST ONLY ON DUMMY DATA)

    Code:
    @echo off
    SETLOCAL ENABLEEXTENSIONS
    for /f "Tokens=*" %%A in ('dir /B /S /A:-D^|FIND /V "%~nx0"') do ECHO del /q "%%A"
    for /f "Tokens=*" %%A in ('dir /B /S /A:D') do ECHO rd /s /q "%%A"
    Last edited by Maqbool; 08-09-2011 at 06:00 AM. Reason: External Links Not Allowed, Removed The Same.

Similar Threads

  1. Creating a batch file to find and delete certain files
    By Damien25 in forum TroubleShoot 98
    Replies: 3
    Last Post: 11-01-2014, 09:58 AM
  2. Need batch file to delete user files in Windows XP
    By mcamp32 in forum Windows XP Support
    Replies: 1
    Last Post: 26-05-2011, 10:54 PM
  3. How to use Batch Files to Create MySQL Database?
    By DANIEL 602 in forum Software Development
    Replies: 4
    Last Post: 05-02-2010, 07:03 AM
  4. Delete the contents of a directory using Batch
    By GUSSIE in forum Operating Systems
    Replies: 3
    Last Post: 11-09-2009, 12:43 PM
  5. Batch file to delete files dynamically
    By freelancer24 in forum Windows Server Help
    Replies: 3
    Last Post: 08-02-2009, 02:33 AM

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,711,633,897.17692 seconds with 17 queries