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

Reply
 
Thread Tools Search this Thread
  #1  
Old 06-01-2009
Member
 
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
Reply With Quote
  #2  
Old 06-01-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
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
Reply With Quote
  #3  
Old 06-01-2009
Member
 
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.
Reply With Quote
  #4  
Old 06-01-2009
Member
 
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.
Reply With Quote
  #5  
Old 06-01-2009
Member
 
Join Date: Nov 2005
Posts: 1,323
Re: Create a batch (. Bat) MS-DOS to delete files

have a look here Creating a batch file to find and delete certain files
Reply With Quote
  #6  
Old 06-01-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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).
Reply With Quote
  #7  
Old 05-09-2011
Member
 
Join Date: Sep 2011
Posts: 3
Re: Create a batch (. Bat) MS-DOS to delete files

Hi

Quote:
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.
Reply With Quote
  #8  
Old 05-09-2011
Member
 
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"
Reply With Quote
  #9  
Old 05-09-2011
Member
 
Join Date: Sep 2011
Posts: 3
Re: Create a batch (. Bat) MS-DOS to delete files

Thanks Janos for your reply ,

Quote:
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"
Reply With Quote
  #10  
Old 08-09-2011
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


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