I have a custom process that is used to distribute financial reports to a client.
A master control file is managed which identifies each person and the respective reports that should be mailed to them. The script then parses each line to extract the "email to" (token 1) and sets all of the attachments (token 2+) in a single variable.
Here is the control file:
Code: Select all
manager1@gmail.com,Epicor_Report_001,Epicor_Report_002,Epicor_Report_003,Epicor_Report_004,Epicor_Report_005,Epicor_Report_006,Epicor_Report_007,Epicor_Report_008
user1@gmail.com,Epicor_Report_001,,,,,,,
user2@gmail.com,Epicor_Report_002,,,,,,,
user3@gmail.com,Epicor_Report_003,,,,,,,
user4@gmail.com,Epicor_Report_004,,,,,,,
user5@gmail.com,Epicor_Report_005,,,,,,,
My question is, is there an easy to way to check the existence of each report (that is set in the variable) and if it doesn't exist, remove it from being set in the variable?
Here are the relevant sections of my script pertaining to this question:
Code: Select all
>>%LOGFILE% (
ECHO ********************************************************
ECHO Execute Financial Report Burst Process
ECHO ********************************************************
ECHO.
)
FOR /F "USEBACKQ Tokens=1* Delims=," %%A IN ( %CNTRL_FILE% ) DO (
CALL :EMAIL "%%A" "%%B|"
)
Code: Select all
:EMAIL
SET "RPT=%~2"
SET /A "LCNT+=1"
SET "SW_SUB=Client : Finance Report Distribution"
SET "SW_BODY=%UTILPATH%SwithMail\Body_Text\FR_DIST_TXT.txt"
SET "SW_TO_EMAIL=%~1"
SET "SW_ATTACH=%RPT:,=|%"
:LOOP
IF "%SW_ATTACH:~-2%"=="||" (
SET "SW_ATTACH=%SW_ATTACH:~0,-1%"
GOTO LOOP
)
SET "SW_ATTACH=%SW_ATTACH:|=.pdf|%"
PUSHD "%RPT_PATH%"
CALL "%SW_MAIL_BIN%SwithMail.exe" /s /x "%SW_MAIL_BIN%SwithMailSettings.xml"^
/SSL /to "%SW_TO_EMAIL%" /sub "%SW_SUB%" /btxt "%SW_BODY%"^
/a "%SW_ATTACH:~0,-1%" && (
ECHO Execute Control File ^- Line %LCNT% : Successful >>%LOGFILE%
) || (
ECHO Execute Control File ^- Line %LCNT% : Failed >>%LOGFILE%
SET "ERR=T"
)
POPD
GOTO :EOF