2010年5月13日 星期四

抽小版的Script

這一個bat script必需要搭配Beyond Compare才能使用

進化版本
sg.bat

@ECHO OFF

REM ========== ----------------------- ==========
REM ========== Solution Generator (sg) ==========
REM ========== ----------------------- ==========

REM ========== INPUT NEW CODE PATH (DO NOT MODIFY) ==========

:TryGetNewPath
SET NEW_CODE_PATH=
SET /P NEW_CODE_PATH=Please input the new(modified) code path (default: %SOURCE_ROOT%\%PROJECT_NAME%):
IF "%NEW_CODE_PATH%" EQU "" SET NEW_CODE_PATH=%SOURCE_ROOT%\%PROJECT_NAME%
IF EXIST %NEW_CODE_PATH% GOTO NewPathOk
ECHO THE PATH DO NOT EXIST, PLEASE INPUT AGAIN
GOTO TryGetNewPath
:NewPathOk

REM ========== INPUT OLD CODE PATH (DO NOT MODIFY) ==========
:TryGetOldPath
SET /P OLD_CODE_PATH=Please input the old(original) code path (ex: d:\work\old\ or d:\work\old.zip):
IF EXIST %OLD_CODE_PATH% GOTO OldPathOk
ECHO THE PATH DO NOT EXIST, PLEASE INPUT AGAIN
GOTO TryGetOldPath
:OldPathOk


REM ======== GET DATE AND TIME (DO NOT MODIFY) ========
FOR /F "tokens=1-4 delims=/ " %%a IN ("%date%") DO (
SET SYS_DATE=%%a.%%b.%%c
)
FOR /F "tokens=1-4 delims=:." %%e IN ("%time%") DO (
SET SYS_TIME=%%e%%f%%g
)

REM ========== INPUT MINI-SOLUTION PATH (DO NOT MODIFY) ==========
SET SOLUTION_PATH=
SET /P SOLUTION_PATH=Please input mini-solution path (default: %SOURCE_ROOT%\%SYS_DATE%-%SYS_TIME%-mini-solution):
IF "%SOLUTION_PATH%" EQU "" SET SOLUTION_PATH=%SOURCE_ROOT%\%SYS_DATE%-%SYS_TIME%-mini-solution

REM ===========================================================
REM User must modify the setting of this block.
REM GENERATE_MODE : SEPARATE_MODE or MERGE_MODE
REM NEW_CODE_PATH : new revision code path
REM OLD_CODE_PATH : old revision code path
REM TARGET_PATH : little version code path
REM SCRIPT_PATH : script file path (solution_generator.script and solution_generator.bat)

SET GENERATE_MODE=SEPARATE_MODE
SET NEW_CODE_PATH=%NEW_CODE_PATH%
SET OLD_CODE_PATH=%OLD_CODE_PATH%
SET TARGET_PATH=%SOLUTION_PATH%
SET SCRIPT_PATH=D:\DEVTLS\BAT

REM ===========================================================
REM Internel path setting , use default path.
REM User can modify these if need.

SET BC2_PATH="C:\Program Files\Beyond Compare 2"
SET TEMP_PATH=C:\TEMP_CODE
IF /I "%GENERATE_MODE%" == "SEPARATE_MODE" SET GENERATE_NEW_CODE=%TARGET_PATH%\NEW
IF /I "%GENERATE_MODE%" == "SEPARATE_MODE" SET GENERATE_OLD_CODE=%TARGET_PATH%\OLD

REM ===========================================================
MKDIR %TARGET_PATH%
IF /I "%GENERATE_MODE%" == "MERGE_MODE" MKDIR %TEMP_PATH%
IF /I "%GENERATE_MODE%" == "SEPARATE_MODE" MKDIR %GENERATE_NEW_CODE%
IF /I "%GENERATE_MODE%" == "SEPARATE_MODE" MKDIR %GENERATE_OLD_CODE%
SET ORIGIN_PATH=%PATH%
SET PATH=%PATH%;%BC2_PATH%
IF /I "%GENERATE_MODE%" == "MERGE_MODE" bc2.exe @%SCRIPT_PATH%\solution_generator.script %NEW_CODE_PATH% %OLD_CODE_PATH% %TARGET_PATH% %TEMP_PATH%
IF /I "%GENERATE_MODE%" == "SEPARATE_MODE" bc2.exe @%SCRIPT_PATH%\solution_generator.script %NEW_CODE_PATH% %OLD_CODE_PATH% %GENERATE_NEW_CODE% %GENERATE_OLD_CODE%
IF /I "%GENERATE_MODE%" == "MERGE_MODE" FOR /R %TEMP_PATH% %%I IN (*.*) DO MOVE /Y %%~fnxI %%~fnxI_
IF /I "%GENERATE_MODE%" == "MERGE_MODE" XCOPY %TEMP_PATH% %TARGET_PATH% /E /K /Y
IF /I "%GENERATE_MODE%" == "MERGE_MODE" RMDIR /S /Q %TEMP_PATH%
SET %PATH%=%ORIGIN_PATH%

REM ========== CREATE NOTE FILE (DO NOT MODIFY) ==========
SET %NoteFile%=%SOLUTION_PATH%\History.txt
ECHO NEW_CODE_PATH: %NEW_CODE_PATH% > %NoteFile%
ECHO OLD_CODE_PATH: %OLD_CODE_PATH% >> %NoteFile%
ECHO MINI-SOLUTION PATH: %SOLUTION_PATH% >> %NoteFile%
ECHO ============================= >> %NoteFile%
ECHO #; Tag: >> %NoteFile%
ECHO #; Issue: >> %NoteFile%
ECHO #; Category: >> %NoteFile%
ECHO #; Symptom: >> %NoteFile%
ECHO #; RootCause: >> %NoteFile%
ECHO #; Solution: >> %NoteFile%
ECHO #; Description: >> %NoteFile%
ECHO #; >> %NoteFile%
ECHO #; Related Files: >> %NoteFile%
ECHO #; Added: > %NoteFile%
ECHO #; Deleted: >> %NoteFile%
ECHO #; Modified: >> %NoteFile%
ECHO #; >> %NoteFile%

PAUSE
REM ===========================================================

solution_generator.script
criteria rules-based
filter "-.svn\";"-uefi64\";"-uefi32\";"-X64\";"-*.Dep";"-_svn\";"-uefi64ddt\"
load "%1" "%2"
expand all
select lt.diff.files lt.orphan.files
copyto lt path:base "%3"
select rt.diff.files rt.orphan.files
copyto rt path:base "%4"


顯示目前目錄底下的所有檔案
% dir /s /b


參考資料:
Eric's Webspace Windows 95 / DOS 7 Batch Programming

沒有留言: