Tiny bit of help with a batch file script...

Hi all, I have the following attached script that runs to search through a bunch of email files (*.eml) and delete them if they match any of the words in the 'spamwords.ext' file.

I need to modify the script so that instead of deleting the .eml files based on whether they match the words in 'spamwords.txt' they are moved to 'd:\email_archive', and then whatever is left in the folder after positive matches are moved is deleted.

Would someone be able to help me modify the script please?

Thanks,


@echo off
setLocal EnableDelayedExpansion
 
pushd D:\IMF_spam_archive
 
for /f "tokens=*" %%w in (spamwords.txt) do (
 
for /f "tokens=* delims= " %%e in ('dir/b/a-d *.eml') do (
find "%%w" < %%e > nul
if not errorlevel 1 del "%%e"
)
)

Open in new window

Nicola_BourneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SteveGTRCommented:
You could do something like this:
@echo off
 
setlocal
 
set srcDir=D:\IMF_spam_archive
set destDir=d:\email_archive
set spamFile=spamwords.txt
 
pushd "%srcDir%"
 
for /f "tokens=*" %%a in ('findstr /G:"%spamFile%" /I /M *.* 2^>NUL') do if /i "%%a" NEQ "%spamFile%" move "%%a" "%destDir%"
 
popd

Open in new window

0
SteveGTRCommented:
Sorry, it gets a lot simpler with the proper mask:
@echo off
 
setlocal
 
set srcDir=D:\IMF_spam_archive
set destDir=d:\email_archive
set spamFile=spamwords.txt
 
pushd "%srcDir%"
 
for /f "tokens=*" %%a in ('findstr /G:"%spamFile%" /I /M *.sml 2^>NUL') do move "%%a" "%destDir%"
 
popd

Open in new window

0
SteveGTRCommented:
Goodness... typo:

*.sml should be *.eml
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Nicola_BourneAuthor Commented:
Thanks Steve, the 'move' bit works perfectly, only it doesn't delete all that is left afterwards yet?

Any further thoughts?

Thanks again.
0
SteveGTRCommented:
So you want to delete all files that don't have spam that are left in the directory?

If so, then you'd just add a del *.eml after the for:
@echo off
 
setlocal
 
set srcDir=D:\IMF_spam_archive
set destDir=d:\email_archive
set spamFile=spamwords.txt
 
pushd "%srcDir%"
 
for /f "tokens=*" %%a in ('findstr /G:"%spamFile%" /I /M *.eml 2^>NUL') do move "%%a" "%destDir%"
 
if exist "*.eml" del *.eml /F /Q
 
popd

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nicola_BourneAuthor Commented:
Yes basically - What was happeneing was we were filtering an insane amount of spam via IMF on Exchange. Some of this was positive email which needed to be kept, so previously we ran a script that deleted from this archive all emails that contained words in a text file. While this worked, it still left too much email to be manageable (i.e. manual searching through to be 'unblocked' - so I'm attempting to change the script to instead move all positive email to a safe location and delete what is left in the folder permanently.

Thanks for all your help - it seems to be working perfectly now :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.