Computing.Net > Forums > Windows XP > Batch file search and delete help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file search and delete help

Reply to Message Icon

Name: Dale_Harry
Date: December 6, 2007 at 04:07:26 Pacific
OS: Win XP
CPU/Ram: Intel Core 2 1.8, 2GB RAM
Product: Dell
Comment:

Hi there,

I need some help where I want to create a small batch file that will search inside all the text files (email files to be precise - *.eml) in a specific given directory (d:\archive) for specific strings.

Basically my plan is this:

We receive a LOT of spam email that is archived. Rather than manually sift through the whole lot I would like to run a batch script on the directory that will search for the specific words such as "Viagra", or "Pills" or etc etc - you know, the normal spam related emails.

The script will have a look in each email; if it finds such a string it will simply delete the file and move on to the next one.

Doing this will automatically eliminate a lot of the bulk of spam, leaving us to search a much smaller amount for false positive emails caught up in the spam filter.

Unfortunately I don't know how to write such a file, so any help would be very gratefully appreciated.

Many thanks,

Dale.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: December 6, 2007 at 06:30:02 Pacific
Reply:

Once you're satisfied it will work, remove the ECHO from the last line to 'activate' it.


=============================
:: delete emails containing spam words

@echo off
setLocal EnableDelayedExpansion

pushd d:\archive

for /f "tokens=* delims= " %%e in ('dir/b/a-d *.eml') do (
for /f "tokens=* delims= " %%a in (%%e) do (
echo %%a | find "viagra" > nul
if not errorlevel 1 echo del %%e
)
)


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 2
Name: Dale_Harry
Date: December 6, 2007 at 07:37:38 Pacific
Reply:

Thanks very much for that, for the 'find' bit, what is the syntax for adding multiple entries?

i.e. Find "Viagra" and "Pills" and "Head" and "Arms" etc?

Many thanks again.


0

Response Number 3
Name: Dale_Harry
Date: December 6, 2007 at 08:10:52 Pacific
Reply:

EDIT:

I've tried the script so far and I see these errors:

http://www.zen87038.zen.co.uk/image...

Any pointers?

Many thanks....


0

Response Number 4
Name: Derek
Date: December 6, 2007 at 13:00:58 Pacific
Reply:

"IF" you are using Outlook or Outlook Express you can do this filtering using email rules. Many spam mails now add text in picture format so neither my suggestion or batch files will find these.

Once you get spam you are stuck with it and "it will keep growing". The only real answer is to change your email address then review your approach. Whatever else you do is fighting a losing battle - I've been down that road.

Never leave your email in "open text" on a website (for example). I have just found yours by simply clicking on your name here then using Google. If Google can find it then the spammers engines will also find it. By now it will be part of data bases that they sell to each other across the world so you can never undo this.

Machines won't click on your name so leaving your email set on this website is "reasonably" safe.

some other bloke...


0

Response Number 5
Name: Dale_Harry
Date: December 7, 2007 at 03:09:58 Pacific
Reply:

Thanks Derek, unfortunately its not really a case of setting up junk email rules on local Outlook accounts. Basically as a company we receive an absolutely ludicrous amount of spam each day already (somewhere near 10,000).
Our external (Linux) mail server handles a fair amount of this, but a lot will sift through to Exchange where IMF filters out the rest. As a result end users actually don't receive much spam at all, but the problem is picking up all the false positives.
Now what we have at the moment is IMF archives all the spam it picks up, we then go through it to check for false positives.
But the majority of spam we receive is in fact text based, and using specific words (although I know exactly what you mean by the image spams) - if I can auto-filter these out with a little script that will delete them, then this is just going to make our job of sifting through the other emails that much quicker.
The issue I have is that I have ZERO experience in writing anything like this - hence the cry for help as I just don't know where to start...



0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: December 7, 2007 at 06:51:17 Pacific
Reply:

I must have been having a senior moment.

::== DELspam3.bat
:: delete emails containing spam words

@echo off
setLocal EnableDelayedExpansion

pushd d:\archive

for /f "tokens=* delims= " %%w in (wordlist) do (

for /f "tokens=* delims= " %%e in ('dir/b/a-d *.eml') do (
find "%%w" < %%e > nul
if not errorlevel 1 del "%%e"
)
)



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 7
Name: Dale_Harry
Date: December 12, 2007 at 02:13:55 Pacific
Reply:

Hi again,

Many thanks for that, I've posted up a link to a screenie of the latest 'error':

http://www.zen87038.zen.co.uk/image...

You can see that I tried to search for the word "afternoon" which was contained inside an email (also pictured) but the batch file returned the error: "The system cannot find the file afternoon."

Not sure if this is a user error by me though!

Thanks so much for all this help.


0

Response Number 8
Name: Mechanix2Go
Date: December 12, 2007 at 05:57:28 Pacific
Reply:

Hi,

I think I goofed. You'd asked if it could search for mulitple 'spam words' so I made the first FOR loop use a list of words {I called it WORDLIST]. You need to create your own list of words. Call it whatever you like, but it must be the file named in the first FOR loop.

I couldn't make anything of that error JPG


=====================================
If at first you don't succeed, you're about average.

M2



0

Sponsored Link
Ads by Google
Reply to Message Icon

System won't boot after M... Media Player won't play A...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Batch file search and delete help

Search and Delete line wit Batfile www.computing.net/answers/windows-xp/search-and-delete-line-wit-batfile/167139.html

Batch file to search and delete file www.computing.net/answers/windows-xp/batch-file-to-search-and-delete-file/177901.html

Delete older files with batch file www.computing.net/answers/windows-xp/delete-older-files-with-batch-file/161017.html