2

我的目标是删除双引号并通过 blat 将 .txt 文件的资源作为正文邮件发送,我已经看到很多关于此的问题(删除双引号).. 但我不知道,我在做什么错误的。这是我的代码

set "now=%date:~4%" 
for /f %%i in ('FORFILES /D %now% /m *.csv /c "cmd /c echo @fname"')
do @set MyVariable=%%~i > C:\temp\count.txt
CD C:\temp\blat3217\full
blat C:\temp\count.txt -p user -s "Incoming_File_Alert" -to mymail@mail.com

编辑:

这给输出空白。

编辑 2:

如果我用这个切换第 2 行FORFILES /D %now% /m *.csv /c "cmd /c echo @fname" > C:\temp\count.txt

输出是这样的

"407232_341600"
"TW39369763_341610"
"1726_341592"
"407316_341601"
"16001_341597"
"100001317_341590"
"407367_341602"
"DHB11838_341593"
"407439_341606"
"407556_341604"
"2373_341595"
"ALL1020-461_341614"
"407382_341605"
"3598_341613"
"PO051334_341589"
"407537_341607"
"407222_341598"
"TW39369964_341611"
"407403_341608"
4

2 回答 2

1

你可以试试这个批处理文件:

@echo off
set "SourcePath=C:\Users\user1\Documents\Work\warehouse\"
set "now="
set "Ext=csv"
Call :GetCurrentDate
set "outputfile=C:\temp\count.txt"
If exist "%outputfile%" Del "%outputfile%"
CD /D "%SourcePath%"
@for /f "delims=" %%i in ('FORFILES /D %now% /m *.%Ext%') do (
    echo %%~ni >> "%outputfile%"
)
If exist "%outputfile%" start "" "%outputfile%" & exit
::********************************************************************************
:GetCurrentDate
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set now=%DD%/%MM%/%YYYY%
exit /b
::********************************************************************************
于 2017-09-13T06:40:15.237 回答
0

感谢 Squashman,他的建议解决了我的问题.. 看起来像这样,如果有人感兴趣的话

CD C:\Users\user1\Documents\Work\warehouse
set "now=%date:~4%"
for /f "delims=" %%i in ('FORFILES /D %now% /m *.csv')do >> C:\temp\count.txt echo %%~ni 
CD C:\temp\blat3217\full
blat C:\temp\count.txt -p user -s "Warehouse_Incoming_File_Alert" -to mymail@mymail.com

编辑1:

输入错误。

编辑2:

如果我们不删除以前存在的 .txt 文件,上面是重复的

这里是添加语法删除以前的文件,感谢Hackoo的回答

CD C:\Users\user1\Documents\Work\warehouse
set "now=%date:~4%"
set "outputfile= C:\temp\count.txt"

If exist %outputfile% del %outputfile%

for /f "delims=" %%i in ('FORFILES /D %now% /m *.csv') do >> %outputfile% echo %%~ni

CD C:\temp\blat3217\full
blat C:\temp\count.txt -p user -s "Warehouse_Incoming_File_Alert" -to  mymail@mymail.com
于 2017-09-13T07:50:15.417 回答