Nicola_Bourne
asked on
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,
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"
)
)
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
Goodness... typo:
*.sml should be *.eml
*.sml should be *.eml
ASKER
Thanks Steve, the 'move' bit works perfectly, only it doesn't delete all that is left afterwards yet?
Any further thoughts?
Thanks again.
Any further thoughts?
Thanks again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 :)
Thanks for all your help - it seems to be working perfectly now :)
Open in new window