bat檔案處理

hexiaomail發表於2010-05-18

::此檔案功能對vss系統資料按單個project作自動備份,在備份之前將對清單檔案做相應處理
::1、刪除所有空行
::2、刪除行首和行尾
::3、用$/替換所有行中$
::4、備份VSS專案
@echo off

cls

set iPath=D:\C#Backup$\script\
set ldFile=%iPath%old.txt
set newFile=%iPath%new.txt
set listFile=%iPath%c#.txt
set TMPFILE=%random%.tmp

set SSDIR=D:\NetApplication\C#
ss Dir $/ -F- > %oldFile%

echo.

echo 正在處理,請稍等...

::刪除第一行
if exist %listFile% (del %listFile%)
more +1 %oldFile% > %newFile%


::刪除最後一行
if exist %oldFile% (del /f/q %oldFile%)
for /f "delims=:" %%i in ('findstr /n . %newFile%') do set n=%%i
set /a nm=%n% >nul
   for /f "delims=" %%i in ('findstr /n .* %newFile%') do (
        set /a mn=%%i 2>nul
        set "m=%%i"
        setlocal enabledelayedexpansion
        set "m=!m:*:=!"
 if !nm! EQU !mn! goto end
echo.!m!>>%oldFile%
endlocal
)
:end

::用$/替換$字元
if exist %newFile% (del /f/q %newFile%)
for /f "delims=:" %%i in ('findstr $ %oldFile%') do (
        set "m=%%i"
 setlocal enabledelayedexpansion
 set b=!m:$=$/!%
      echo !b!>>%newFile%
endlocal
)


::刪除空行
for /f "delims=^" %%k in (%newFile%) do (if not %%k == "" echo %%k >> %listFile%)


::刪除臨時檔案
if exist %oldFile% (del /f/q %oldFile%)
if exist %newFile% (del /f/q %newFile%)
echo.

for /f "delims=" %%a in ('findstr . %listFile%') do ssarc.exe -d- -s"D:\NetApplication\C#" -i-Y -yadmin,Fihvss123 -O@"D:\C#Backup%%aBak_%date:~0,10%.txt" "D:\C#Backup%%aBak_%date:~0,10%.ssa" %%a

ECHO 任務完成,請按任意鍵檢視生成結果...

::pause >nul

::start %newFile%

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9932141/viewspace-662941/,如需轉載,請註明出處,否則將追究法律責任。

相關文章