anub13
anub13

Reputation: 69

Batch file, removing double quote but giving blank .txt

My goal is to remove the double quote and send resource of .txt file as body mail through blat, I've seen a lot of question regarding this(removing double quotes).. but I can't figure out, where am I doing wrong. Here is my code

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 [email protected]

EDIT:

This giving output blank.

EDIT 2 :

if I switch out line number 2 with this FORFILES /D %now% /m *.csv /c "cmd /c echo @fname" > C:\temp\count.txt

The output is like this

"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"

Upvotes: 2

Views: 80

Answers (2)

anub13
anub13

Reputation: 69

Thanks to Squashman, my problem solved with his suggestion.. looked like this, if anyone interested

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 [email protected]

EDIT 1:

Mistype.

EDIT 2:

Above is duplicating if we don't delete previous existing .txt file

here is adding syntax delete previous file, thanks to Hackoo answer

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  [email protected]

Upvotes: 0

Hackoo
Hackoo

Reputation: 18837

You can give a try for this batch file :

@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
::********************************************************************************

Upvotes: 1

Related Questions