:BEGIN @echo off @echo Save old log file if exist GOTO SAVE echo "No file to save" :START echo Start logging... start putty.exe -load "SESSIONNAME" GOTO END :SAVE setlocal set /a cnt = 0 :LOOP: set /a cnt += 1 if exist %cnt% GOTO LOOP copy %cnt% del echo Last file saved as %cnt% GOTO START :END @echo on @exit 0