سؤال

What and Why?

I know how to use Blat. That is not the issue.

Have already done this using Powershell and VBS.. However, my colleagues have asked me to re-work this in Batch.

We have enterprise security restrictions with VBS and we have to sign all of our code now. Powershell is OK, but... Batch gives us a nice albeit old platform and everybody on our team understands.

Background

We are reading a mapping.txt file for a list of companies and e-mails.

Trying to sort out how to attach one or more files to an e-mail using a batch file to be sent using blat.

For example (NOTE: The comma between the two files listed below):

-attach "20131208_Company_UsageReport.zip,20131208_Company_ActivityReport.zip"

Per Blat's help (-h) switch we see the following for handling attachments:

 ----------------------- Attachment and encoding options -----------------------
 -attach <file>  : attach binary file(s) to message (filenames comma separated)
 -attacht <file> : attach text file(s) to message (filenames comma separated)
 -attachi <file> : attach text file(s) as INLINE (filenames comma separated)
 -embed <file>   : embed file(s) in HTML.  Object tag in HTML must specify
                   content-id using cid: tag.  eg: <img src="cid:image.jpg">
 -af <file>      : file containing list of binary file(s) to attach (comma separated)
 -atf <file>     : file containing list of text file(s) to attach (comma separated)
 -aef <file>     : file containing list of embed file(s) to attach (comma separated)

What have I done so far? Borrowing from - How to concatenate variable with string or variable in batch file

SETLOCAL EnableDelayedExpansion
for /f "delims=" %%P in ('dir /b "C:\Batch\*Company*"') do (
  SET "sZIPName=%%~nxP"
  echo first stop
  echo !sZIPName:~0,1!
  IF "!sZIPName:~0,1!" NEQ "1" (SET "sZIPName=!sZIPName:~0,1!") && SET myvar=!myvar!%%P
  IF "!sZIPName:~0,1!" EQU "1" (SET "sZIPName=!sZIPName:~0,1!") && SET myvar=!myvar!%%P
  rem SET tempStr=GEN !sZIPName! 

  echo second stop
  echo "!myvar! "
  rem echo "!tempStr!"
  rem echo "!sZIPName!"
  pause
  rem for /f "delims=" %%H in ('dir /b *.html') do (
  rem   IF "!sZIPName:~-0!"=="!%%H:~0,1!" echo %%H
  rem )
)

I know I can do the following:

IF "!sZIPName:~0,1!" NEQ "1" (SET "sZIPName=!sZIPName:~0,1!") && SET myvar=!myvar!%%P,

But produces results like:

"20131208_Company_UsageReport.zip,20131208_Company_ActivityReport.zip, "
هل كانت مفيدة؟

المحلول

Is this what you're looking for?

@echo off
setlocal enabledelayedexpansion

for /f %%a in ('dir /b *company*.zip') do (
  set write=!write!%%a,
)
echo -attach !write:~0,-1!
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top