batch批處理小記

說明

批處理(Batch),也稱爲批處理腳本,它應用於DOS和Windows系統中。

命令

echo

說明:打開回顯或關閉請求回顯功能,或顯示消息。

rem

說明:註釋命令,它並不會被執行,只是起一個註釋的作用。

pause

說明:暫停命令。運行 Pause 命令時,將顯示消息:Press any key to continue. . .(或:請按任意鍵繼續. . .)

call

說明:從一個批處理程序調用另一個批處理程序,並且不終止父批處理程序。

start

說明:調用外部程序,所有的DOS命令和命令行程序都可以由start命令來調用。

goto

說明:跳轉命令。程序指針跳轉到指定的標籤(前面加:表示這是標籤),從標籤後的第一條命令開始繼續執行批處理程序。

set

說明:顯示、設置或刪除變量。

符號

重定向符號 ( 輸出 >與>> ) 和 ( 輸入 < )

管道符號 |

轉義符 ^ 和 %

邏輯命令符(&與&&與||)

案例

拖拽文件夾到bat文件上,修改相關內容

@echo off
echo Start Modify

REM 編碼utf-8
chcp 65001

IF "%~1" == "" GOTO ERROR
IF NOT EXIST "%~1" GOTO ERROR

cd /d %~1
REM echo %cd%
echo del .exe file
del *.exe

echo rmdir vriamges
rd /s/q .\vriamges

echo replace addr and modify 1e3 to 2e3
set dist_js=\dist\js\app.39700d7c.js
set dist_js1=\dist\js\app.39700d7c_1.js

set f1=%cd%%dist_js%
set f2=%cd%%dist_js1%

REM echo %f1%
REM echo %f2%

if not exist %f1% GOTO ERROR
if not exist %f2% GOTO ERROR

set addr_external=http://192.168.3.20:81/dispatch/infoRealTimeData
set addr_internal=http://192.168.0.12:8080/HZSWDD/dispatch/infoRealTimeData

set time_external=1e3
set time_internal=2e3

REM echo %addr_external%
REM echo %addr_internal%

for /f "delims=" %%i in ('type "%f1%"') do (
    set str=%%i
	setlocal EnableDelayedExpansion
	set str=!str:%addr_external%=%addr_internal%!
	set str=!str:%time_external%=%time_internal%!
	echo !str!>>%f1%.bk
	endlocal
)
move "%f1%.bk" "%f1%"

for /f "delims=" %%i in ('type "%f2%"') do (
    set str=%%i
	setlocal EnableDelayedExpansion
	set str=!str:%addr_external%=%addr_internal%!
	set str=!str:%time_external%=%time_internal%!
	echo !str!>>%f2%.bk
	endlocal
)
move "%f2%.bk" "%f2%"

echo copy png image
REM set image3d_origin=%cd%\resource\images\26d185ddb4e5d092.png
set image3d_origin=%cd%\resource\images\f9f1e4ead85bc5f3.png
set image3d_new=%~dp0\assets\image3d.png
if not exist %image3d_origin% GOTO ERROR
if not exist %image3d_new% GOTO ERROR
copy "%image3d_new%" "%image3d_origin%"

echo all modify complete!
pause
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章