T3RRYT3RR0R

Batch Label Tracking

Feb 8th, 2020
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.04 KB | None | 0 0
  1. @echo off
  2.  
  3. REM Establish path, directory, and file for Log
  4.     Set "ProgLoc=%~dp0"
  5.     IF Not Exist "%ProgLoc%\Logs" MD "%ProgLoc%\Logs"
  6.     Set "LogDir=%ProgLoc%Logs"
  7.     Set "Log_File=%LogDir%\LastRun.log"
  8.  
  9. REM Use set substring modification to store runtime in variable
  10.     Set "DT_String=%DATE:/=%_At_%TIME::=%"
  11.     Set "DT_String=%DT_String:.=%"
  12.     Set "DT_String=%DT_String: =0%"
  13.     Set "DT_String=%DT_String:~4,16%"
  14.  
  15. REM Function call in variable form
  16.     Set "@_Track=Call :Track_Log"
  17.  
  18. REM Overwrite last runtime log
  19.     ECHO(Last Run # %DT_String%>"%Log_File%"
  20.     GOTO :main
  21.  
  22. REM Function to store the current Label in the Log using the @_Track variable macro and parameter.
  23. :Track_Log
  24.     Echo(%1>>"%Log_File%"
  25.     Exit /b
  26.  
  27. REM The Below script is an Example of using the @_Track variable to store the current Label to the log.
  28. :first
  29.     ECHO(Here
  30.     %@_Track% first
  31.     Exit /b
  32.  
  33. :second
  34.     ECHO(And
  35.     %@_Track% second
  36.     Exit /b
  37.  
  38. :third
  39.     ECHO(There
  40.     %@_Track% third
  41.     Exit /b
  42.  
  43. :main
  44.     For %%A IN (first,second,third) DO (
  45.         CALL :%%A
  46.     )
  47. TYPE "%Log_File%"
  48. Pause
Advertisement
Add Comment
Please, Sign In to add comment