在Windows開發中,在batch腳本中常需要獲取一個文件中的某個參數的值,我們可以這樣處理:
<pre name="code" class="plain">@set VERSION_FILE_PATH=../../apps/common_app/userapp/interface.c
@sed -n -e 's/#define[ \t]*SW_VERSION_PLAY[ \t]*[\(]*[ \t]*\([0-9]*\)[ \t]*[\)]*.*$/\1/p' %VERSION_FILE_PATH% > ver.txt
@set /p SW_VER= < ver.txt
@del ver.txt
@set SW_VER_HIGH=%SW_VER:~0,-2%
@set SW_VER_LOW=%SW_VER:~-2,2%
上面是獲取interface.c中的SW_VERSION_PLAY 的值是多少
batch 中獲取當前時間:
@set year=%date:~0,4%
@set month=%date:~5,2%
@set day=%date:~8,2%
copy MT_play_update.bin ..\play\Normal\Mango_Play_V%SW_VER_HIGH%.%SW_VER_LOW%_%day%-%month%-%year%.bin
判斷一個文件是否大於12K 的操作。
for /f "delims=" %%a in ('dir /b ME_Africa_sattp_S2.bin') do set /a "s+=%%~za/1024"
if %s% geq 12 (
echo login compress, is compress sattp.bin file.
compress.exe ME_Africa_sattp_S2.bin "TP" compress_sattp.bin
copy compress_sattp.bin ME_Africa_sattp_S2.bin
del compress_sattp.bin
) else (
echo no compress,files are already compressed.
)
if exist ME_Africa_sattp_S2.bin (
echo "ME_Africa_sattp_S2.bin exist"
) else (
echo "ME_Africa_sattp_S2.bin No exist"
SatTPClient.exe ME_Africa_sattp_S2.cfg ME_Africa_sattp_S2.bin
)