我正在處理測試執行的痕跡。有一個文件(traces/trace.txt),最後一個測試的跟蹤存儲在那裏,我想編寫一個腳本來存儲這個文件的舊版本。使用.bat腳本自動執行文件複製
這裏是我做了什麼:
-created一個文件夾
我已經寫了一個腳本「trace_archive.bat」關於複製與跟蹤文件到這個文件夾和連接文件版本「AllTraces」日期和時間的名稱:
set source=c:\some_path\traces\trace.txt
set destination=c:\somepath\AllTraces\
xcopy %source% %destination% /y
cd %destination%
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I
set datetime=%datetime:~0,8%-%datetime:~8,6%
ren "trace.txt" "trace_%datetime%.txt"
所以,在此文件夾中,我將有一個名字像這樣的文件:
trace_20161117-095910.txt
trace_20161117-105713.txt
等
-created文件夾 「LastTrace」
的想法是存儲副本最後一個跟蹤版本的跟蹤並將trace/trace.txt與它比較。如果有差異,那麼現在我們已經執行了新的測試,因此我們啓動trace_archive.txt來創建副本,並將LastTrace中的trace.txt替換爲當前版本的trace/trace.txt。 所以,我創建了一個腳本「TraceTrigger.bat」:
set noDiff = "FC: no differences encountered"
FOR /F "tokens=* USEBACKQ" %%F IN (`fc /b C:\some_path\AllTraces\LastTrace\trace.txt c:\some_path\traces\trace.txt`)
DO (
SET result=%%F
)
if NOT %noDiff% == %result% (
c:some_path\scripts\trace_archive.bat
del /f c:sope_path\AllTraces\LastTrace\trace.txt
xcopy c:\Users\akomedat\AppData\Local\Temp\.FLT\traces\trace.txt c:Users\akomedat\AllTraces\LastTrace\
)
預期該腳本不起作用。當然,它不會執行trace_archive.bat,也不會將文件複製到discuces。這裏是我得到的輸出:
C:\some_path\scripts>TraceTrigger.bat
C:\some_path\scripts>set noDiff = "FC: no differences encountered"
C:\some_path\scripts>FOR /F "tokens=* USEBACKQ" %F IN (`fc /b C:\some_path\AllTraces\LastTrace\trace.txt c:\some_path\tra
ces\trace.txt`) DO (SET result=%F)
C:\some_path\scripts>(SET result=Comparing files C:\some_path\ALLTRACE
S\LASTTRACE\trace.txt and C:\some_path\TRACES\TRACE
.TXT)
C:\some_path\scripts>(SET result=FC: C:\some_path\ALLTRACES\LASTTRACE\
trace.txt longer than C:\some_path\TRACE.TXT
)
C:\some_path\ALLTRACES\LASTTRACE\trace.txt was unexpected at this time.
C:\some_path\scripts>if NOT == FC: C:\some_path\ALLTRACES\LASTTRACE\t
race.txt longer than C:\some_path\TRACES\TRACE.TXT
(
如何修復TraceTrigger.bat?