2017-09-13 90 views
2

我的目標是通過blat刪除雙引號和發送.txt文件的資源作爲正文郵件,我見過很多關於此問題的問題(刪除雙引號) ..但我無法弄清楚,我在哪裏做錯了。這裏是我的代碼批處理文件,刪除雙引號,但給空白.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 [email protected] 

編輯:

這使輸出空白。

編輯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" 
+0

這雙引號?我看到三套。 – SomethingDark

+0

@ anub13,請刪除您的意見,並編輯您的問題與任何額外的信息。 – Squashman

+0

'DO'必須和'FOR'在同一行。我認爲你想要做的是這個。 'for/f「delims =」%% i in('FORFILES/D%now%/ m * .csv')do >> C:\ temp \ count.txt echo %%〜ni' – Squashman

回答

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 
::******************************************************************************** 
+0

在重定向輸出之前,不需要將FOR變量設置爲環境變量。也不應該需要'/ c「cmd/c echo @fname」'因爲你可以在不帶'FOR'變量修飾符的擴展名的情況下獲得基本文件名。因此,基本代碼可能看起來像這樣:'for/f「delims =」%% i in('FORFILES/D%now%/ m * .csv')>> C:\ temp \ count.txt echo %%〜ni' – Squashman

+0

嗨Hackoo, 感謝您的迴應,剛纔運行您的建議,它不會給出輸出。相反,它打開新的.txt文件,並寫了 !MyVariable! – anub13

+0

@ anub13檢查我最後一次編輯根據Squashman的評論 – Hackoo

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

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