Batch to delete specific files in specific location

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
data808
Posts: 47
Joined: 19 Jul 2012 01:49

Batch to delete specific files in specific location

#1 Post by data808 » 18 Jan 2014 02:15

I wanted to make a batch file that deletes a certain type of file (probably a .txt file) that pops up on the desktop every so often. I believe its java runtime error logs and the better solution would be to update our java program but that is not an option at this time. I would also like to put this batch file in the start up folder of a computer so it executes everytime I turn on the computer. If it can possibly work on winxp and win7 that would be awesome. Just want to get rid of these annoying files for the time being. Thanks.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch to delete specific files in specific location

#2 Post by foxidrive » 18 Jan 2014 02:19

This will delete a file called file.log from the desktop. Put it in the startup group.

Code: Select all

@echo off
del "%userprofile%\desktop\file.log"

data808
Posts: 47
Joined: 19 Jul 2012 01:49

Re: Batch to delete specific files in specific location

#3 Post by data808 » 19 Jan 2014 13:56

Thank you. That's pretty good but what if the files have different names? Would I be able to use some wildcards to get it close but not exact on the file name? I think they all look like a .txt file and they all start with the letter "h" in the beginning of the file name. I have to go check. Let me know if this is possible. Thanks for your help.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Batch to delete specific files in specific location

#4 Post by Squashman » 19 Jan 2014 14:56

yes. You can use * and ? to match file names.
H*.txt would delete all text files that start with an H.

data808
Posts: 47
Joined: 19 Jul 2012 01:49

Re: Batch to delete specific files in specific location

#5 Post by data808 » 21 Jan 2014 13:45

thanks so much. i will try it out. so * and ? does the same thing?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Batch to delete specific files in specific location

#6 Post by Squashman » 21 Jan 2014 13:53

data808 wrote:thanks so much. i will try it out. so * and ? does the same thing?

A quick Google search would probably give you the answer but I did that for you.
http://www.microsoft.com/resources/docu ... x?mfr=true

data808
Posts: 47
Joined: 19 Jul 2012 01:49

Re: Batch to delete specific files in specific location

#7 Post by data808 » 23 Jan 2014 00:17

Just wanted to come back and let you know that I tried your batch file and it worked like a charm. Thanks so much for your help.

Post Reply