[Batch] 讀取文字檔

剛才已經提過利用Powershell 進行文字檔讀取, 而在Batch 中進行的話, 則需要透過for do 進行.

@echo off
set defaultBusinessDatePath=C:\iBossDayEndProcess\DefaultBusinessDate.txt
for /f "delims=" %%x in (%defaultBusinessDatePath%) do set CurrentDate=%%x
echo CurrentDate: %CurrentDate%

利用For /f 設定讀取檔案, 並讀取每一行並執行指令, 在例子中則只讀取最後一行並assign 到variable 中.

參考資料

For, ss64,
https://ss64.com/nt/for_f.html

About C.H. Ling 262 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.