옥수수 농장
카테고리 전체
(121)
programmer
(82)
program & app
(5)
android
(65)
mfc
(2)
web script
(6)
database
(2)
dos macro(batch)
(1)
computer
(28)
idea
(0)
information
(10)
주인장
전체 포스팅
포스팅
/
/
블로그 내 검색
[Macro] File parsing, copy, compress, error control
ocsoosoo
2014. 11. 6. 14:01
2014. 11. 6. 14:01
1. setlocal 내에서 값이 바뀌는 경우 !로 변수 사용, 값이 바뀌지 않는 경우 %로 변수 사용.
2. 출력을 파일로 할 경우 errorlevel이 설정되지 않는다.
build.bat
@ECHO OFF & cls rem ______input_folder__________ set CONFIG_FILE=config.txt set IN_DOC_FOLDER=..\doc set IN_SOURCE_FOLDER=..\src rem ______output_folder__________ set OUT_DOC_FOLDER=document set OUT_SOURCE_FOLDER=source set OUT_ARCHIVE_FOLDER=archive rem ______input_items__________ set SOURCE_FOLDER=src set SOLUTION_FILE=*.sln set PROJECT_FILE=*.prj rem ______Log_file__________ set DATESTAMP=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2% set TIMESTAMP=%TIME:~0,2%%TIME:~3,2%%TIME:~6,2% set LOGFILENAME=release%DATESTAMP%_%TIMESTAMP%.log rem ______Release_Parameters__________ set SECTION_NAME_VER=[Version] set SECTION_NAME_APP=[App] set SECTION_NAME_DOC=[Documents] set PARAM_FIRM_VER=FIRMWARE_VER set PARAM_DRV_VER=DRIVER_VER set PARAM_APP_VER=APP_VER rem ______START_OF_LOCAL__________ setlocal enableextensions enabledelayedexpansion set XCOPY_ERROR_PARAM1="" set XCOPY_ERROR_PARAM2="" set COMPRESS_ERR_PARAM="" set app_count=0 set doc_count=0 rem ______Check_to_CONFIG_FILE_existence__________ if not exist !CONFIG_FILE! ( echo Can not find !CONFIG_FILE! 2>&1 | wtee -a %LOGFILENAME% goto FINAL ) ::make & clean output folder if exist %OUT_DOC_FOLDER% rd /s /q %OUT_DOC_FOLDER% if exist %OUT_ARCHIVE_FOLDER% rd /s /q %OUT_ARCHIVE_FOLDER% if exist %OUT_SOURCE_FOLDER% rd /s /q %OUT_SOURCE_FOLDER% del *.log md %OUT_DOC_FOLDER% md %OUT_ARCHIVE_FOLDER% md %OUT_SOURCE_FOLDER% rem ______Versions__________ echo ========== Versions Section ========== 2>&1 | wtee -a %LOGFILENAME% for /f "tokens=*" %%a in (%CONFIG_FILE%) do ( set item=%%a if "!SECTION_NAME_VER!"=="!item!" ( set ver_section=1 ) else if defined ver_section ( if not !item!=="" if not "!item:~0,1!"=="[" ( echo --------------- 2>&1 | wtee -a %LOGFILENAME% echo !item! 2>&1 | wtee -a %LOGFILENAME% for /f "tokens=1,2 delims==" %%b in ("!item!") do ( set currkey=%%b set currval=%%c if !currkey!==!PARAM_FIRM_VER! ( set found_firm_ver=!currval! echo Firmware version: !found_firm_ver! 2>&1 | wtee -a %LOGFILENAME% ) if !currkey!==!PARAM_DRV_VER! ( set found_drv_ver=!currval! echo Driver version: !found_drv_ver! 2>&1 | wtee -a %LOGFILENAME% ) if !currkey!==!PARAM_APP_VER! ( set found_app_ver=!currval! echo App version: !found_app_ver! 2>&1 | wtee -a %LOGFILENAME% ) if defined found_firm_ver if defined found_drv_ver if defined found_app_ver ( goto END_OF_VERSION_SECTION ) ) ) else ( goto END_OF_VERSION_SECTION ) ) ) :END_OF_VERSION_SECTION if not defined found_firm_ver goto ERR_FIRM_VER if not defined found_drv_ver goto ERR_DRV_VER if not defined found_app_ver goto ERR_APP_VER rem ______app__________ echo ========== App Section ========== 2>&1 | wtee -a %LOGFILENAME% for /f "tokens=*" %%a in (!CONFIG_FILE!) do ( set item=%%a if "!SECTION_NAME_APP!"=="!item!" ( set app_section=1 ) else if defined app_section ( if not !item!=="" if not "!item:~0,1!"=="[" ( echo --------------- 2>&1 | wtee -a %LOGFILENAME% echo !item! 2>&1 | wtee -a %LOGFILENAME% xcopy /s /i /F /K /Y /Q !IN_SOURCE_FOLDER!\!item!\!SOURCE_FOLDER! %OUT_SOURCE_FOLDER%\!item!\!SOURCE_FOLDER! if not "!errorlevel!"=="0" ( set XCOPY_ERROR_PARAM1=!item!\!SOURCE_FOLDER! set XCOPY_ERROR_PARAM2=!errorlevel! goto ERR_XCOPY ) echo !item!\!SOURCE_FOLDER! copied. 2>&1 | wtee -a %LOGFILENAME% xcopy /F /K /Y /Q !IN_SOURCE_FOLDER!\!item!\!SOLUTION_FILE! %OUT_SOURCE_FOLDER%\!item!\!SOLUTION_FILE! if not "!errorlevel!"=="0" ( set XCOPY_ERROR_PARAM1=!item!\!SOLUTION_FILE! set XCOPY_ERROR_PARAM2=!errorlevel! goto ERR_XCOPY ) echo !item!\!SOLUTION_FILE! copied. 2>&1 | wtee -a %LOGFILENAME% xcopy /F /K /Y /Q !IN_SOURCE_FOLDER!\!item!\!PROJECT_FILE! %OUT_SOURCE_FOLDER%\!item!\!PROJECT_FILE! if not "!errorlevel!"=="0" ( set XCOPY_ERROR_PARAM1=!item!\!PROJECT_FILE! set XCOPY_ERROR_PARAM2=!errorlevel! goto ERR_XCOPY ) echo !item!\!PROJECT_FILE! copied. 2>&1 | wtee -a %LOGFILENAME% set /A app_count = !app_count!+1 ) else ( goto END_OF_APP_SECTION ) ) ) :END_OF_APP_SECTION echo App count : !app_count! 2>&1 | wtee -a %LOGFILENAME% if !app_count! lss 1 goto ERROR_APP_COUNT rem ______Documents__________ echo ========== Document Section ========== 2>&1 | wtee -a %LOGFILENAME% for /f "tokens=*" %%a in (!CONFIG_FILE!) do ( set item=%%a if "!SECTION_NAME_DOC!"=="!item!" ( set doc_section=1 ) else if defined doc_section ( if not !item!=="" if not "!item:~0,1!"=="[" ( echo --------------- 2>&1 | wtee -a %LOGFILENAME% echo !item! 2>&1 | wtee -a %LOGFILENAME% echo f | xcopy /E /K /Y /Q /I !IN_DOC_FOLDER!\!item! %OUT_DOC_FOLDER%\!item! if not "!errorlevel!"=="0" ( set XCOPY_ERROR_PARAM1=!item! set XCOPY_ERROR_PARAM2=!errorlevel! goto ERR_XCOPY ) echo !item! copied. 2>&1 | wtee -a %LOGFILENAME% set /A doc_count = !doc_count!+1 ) else ( goto END_OF_DOUCMENT_SECTION ) ) ) :END_OF_DOUCMENT_SECTION echo Document count : !doc_count! 2>&1 | wtee -a %LOGFILENAME% if !doc_count! lss 1 goto ERROR_DOC_COUNT rem ______Compress__________ endlocal & SET APP_COUNT=%app_count%& SET DOC_COUNT=%doc_count%& SET FIRM_VER=%found_firm_ver%& SET DRV_VER=%found_drv_ver%& SET APP_VER=%found_app_ver% 7z a -tzip %OUT_ARCHIVE_FOLDER%\Apps_v%APP_VER%_%DATESTAMP%.zip %CONFIG_FILE% -ir!%OUT_DOC_FOLDER%\* -ir!%OUT_SOURCE_FOLDER%\* if not "%errorlevel%"=="0" ( set COMPRESS_ERR_PARAM=%errorlevel% goto ERR_COMPRESS ) rem ______Success_Result__________ echo OK. 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ######## ### ###### ###### ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ######## ## ## ###### ###### ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ######### ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ###### ###### ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo Firmware version: %FIRM_VER% 2>&1 | wtee -a %LOGFILENAME% echo Driver version: %DRV_VER% 2>&1 | wtee -a %LOGFILENAME% echo App version: %APP_VER% 2>&1 | wtee -a %LOGFILENAME% echo %APP_COUNT% App are copied. 2>&1 | wtee -a %LOGFILENAME% echo %DOC_COUNT% Documents are copied. 2>&1 | wtee -a %LOGFILENAME% echo Archive created: %OUT_ARCHIVE_FOLDER%\release_ver%APP_VER%.zip 2>&1 | wtee -a %LOGFILENAME% goto FINAL :ERR_FIRM_VER echo Fail. 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ######## ### #### ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ###### ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ######### ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## #### ######## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo [ERROR] Firmware version error!!! 2>&1 | wtee -a %LOGFILENAME% goto FINAL :ERR_DRV_VER echo Fail. 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ######## ### #### ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ###### ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ######### ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## #### ######## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo [ERROR] Driver version error!!! 2>&1 | wtee -a %LOGFILENAME% goto FINAL :ERR_APP_VER echo Fail. 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ######## ### #### ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ###### ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ######### ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## #### ######## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo [ERROR] App version error!!! 2>&1 | wtee -a %LOGFILENAME% goto FINAL :ERROR_APP_COUNT echo Fail. 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ######## ### #### ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ###### ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ######### ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## #### ######## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo [ERROR] App count error!!!! 2>&1 | wtee -a %LOGFILENAME% goto FINAL :ERROR_DOC_COUNT echo Fail. 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ######## ### #### ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ###### ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ######### ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## #### ######## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo [ERROR] Document count error!!!! 2>&1 | wtee -a %LOGFILENAME% goto FINAL :ERR_XCOPY echo Fail. 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ######## ### #### ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ###### ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ######### ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## #### ######## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% if "!XCOPY_ERROR_PARAM2!"=="1" echo [ERROR] !XCOPY_ERROR_PARAM1! - (!XCOPY_ERROR_PARAM2!) No files were found to copy. 2>&1 | wtee -a %LOGFILENAME% if "!XCOPY_ERROR_PARAM2!"=="2" echo [ERROR] !XCOPY_ERROR_PARAM1! - (!XCOPY_ERROR_PARAM2!) The user pressed CTRL+C to terminate xcopy. 2>&1 | wtee -a %LOGFILENAME% if "!XCOPY_ERROR_PARAM2!"=="4" echo [ERROR] !XCOPY_ERROR_PARAM1! - (!XCOPY_ERROR_PARAM2!) Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line. 2>&1 | wtee -a %LOGFILENAME% if "!XCOPY_ERROR_PARAM2!"=="5" echo [ERROR] !XCOPY_ERROR_PARAM1! - (!XCOPY_ERROR_PARAM2!) Disk write error occurred. 2>&1 | wtee -a %LOGFILENAME% goto FINAL :ERR_COMPRESS echo Fail. 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ######## ### #### ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ###### ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ######### ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## ## ## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## ## ## #### ######## ## 2>&1 | wtee -a %LOGFILENAME% echo ## ## 2>&1 | wtee -a %LOGFILENAME% echo ######################################################### 2>&1 | wtee -a %LOGFILENAME% if "%COMPRESS_ERR_PARAM%"=="1" echo [ERROR] Compress error!!! - (%COMPRESS_ERR_PARAM%) Warning. Non fatal error(s) occurred. 2>&1 | wtee -a %LOGFILENAME% if "%COMPRESS_ERR_PARAM%"=="2" echo [ERROR] Compress error!!! - (%COMPRESS_ERR_PARAM%) A fatal error occurred. 2>&1 | wtee -a %LOGFILENAME% if "%COMPRESS_ERR_PARAM%"=="3" echo [ERROR] Compress error!!! - (%COMPRESS_ERR_PARAM%) A CRC error occurred when unpacking. 2>&1 | wtee -a %LOGFILENAME% if "%COMPRESS_ERR_PARAM%"=="4" echo [ERROR] Compress error!!! - (%COMPRESS_ERR_PARAM%) Attempt to modify an archive previously locked. 2>&1 | wtee -a %LOGFILENAME% if "%COMPRESS_ERR_PARAM%"=="5" echo [ERROR] Compress error!!! - (%COMPRESS_ERR_PARAM%) Write to disk error. 2>&1 | wtee -a %LOGFILENAME% if "%COMPRESS_ERR_PARAM%"=="6" echo [ERROR] Compress error!!! - (%COMPRESS_ERR_PARAM%) Open file error. 2>&1 | wtee -a %LOGFILENAME% if "%COMPRESS_ERR_PARAM%"=="7" echo [ERROR] Compress error!!! - (%COMPRESS_ERR_PARAM%) Command line option error. 2>&1 | wtee -a %LOGFILENAME% if "%COMPRESS_ERR_PARAM%"=="8" echo [ERROR] Compress error!!! - (%COMPRESS_ERR_PARAM%) Not enough memory for operation. 2>&1 | wtee -a %LOGFILENAME% if "%COMPRESS_ERR_PARAM%"=="9" echo [ERROR] Compress error!!! - (%COMPRESS_ERR_PARAM%) Create file error. 2>&1 | wtee -a %LOGFILENAME% if "%COMPRESS_ERR_PARAM%"=="255" echo [ERROR] Compress error!!! - (%COMPRESS_ERR_PARAM%) User stopped the process. 2>&1 | wtee -a %LOGFILENAME% goto FINAL :FINAL exit /b endlocal
config.txt
[Version] FIRMWARE_VER=17.1 DRIVER_VER=17.1 APP_VER=2.1 [App] application_name1 application_name2 application_name3 application_name4 [Documents] Apps_note.docx
공유하기
게시글 관리
옥수수 농장
저작자표시
비영리
변경금지
+ Recent posts
Powered by
Tistory
, Designed by
wallel
Rss Feed
and
Twitter
,
Facebook
,
Youtube
,
Google+
티스토리툴바