我的目标是删除双引号并通过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:
如果我使用此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"
答案 0 :(得分: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
::********************************************************************************
答案 1 :(得分: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