什么和为什么?
我知道如何使用Blat。这不是问题。
已经使用Powershell和VBS完成了这项工作。但是,我的同事已要求我在批处理中重新进行此操作。
我们对VBS有企业安全限制,我们现在必须签署所有代码。 Powershell还可以,但是... Batch为我们提供了一个不错的旧平台,我们团队中的每个人都理解。
背景
我们正在阅读一个mapping.txt文件,以获取公司和电子邮件列表。
尝试使用blat发送批处理文件来解决如何将一个或多个文件附加到电子邮件的问题。
例如(注意:下面列出的两个文件之间的逗号):
-attach "20131208_Company_UsageReport.zip,20131208_Company_ActivityReport.zip"
Per Blat的帮助(-h)切换我们看到以下处理附件:
----------------------- 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)
到目前为止我做了什么? 借用 - 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 )
)
我知道我可以做到以下几点:
IF "!sZIPName:~0,1!" NEQ "1" (SET "sZIPName=!sZIPName:~0,1!") && SET myvar=!myvar!%%P,
但产生的结果如下:
"20131208_Company_UsageReport.zip,20131208_Company_ActivityReport.zip, "
答案 0 :(得分:1)
这是你要找的吗?
@echo off
setlocal enabledelayedexpansion
for /f %%a in ('dir /b *company*.zip') do (
set write=!write!%%a,
)
echo -attach !write:~0,-1!