A simple bat file template: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary Tags: Mobile edit Mobile web edit |
mNo edit summary Tags: Mobile edit Mobile web edit |
||
| Line 33: | Line 33: | ||
</pre> | </pre> | ||
[[Category: MS-DOS]] [[Category: Bash]] [[Category: Tool]] | [[Category: MS-DOS]] [[Category: Bash]] [[Category: Tool]] [[Category: Template]] | ||
Revision as of 10:33, 4 March 2024
A simple bat file template
@ECHO OFF
SETLOCAL EnableExtensions
SET MY_DATETIME=%DATE%-%TIME%
SET MY_FILENAME=%~n0
TITLE %MY_FILENAME% - %MY_DATETIME%
REM Example script operations
ECHO Starting script operations...
REM Example of logging
SET LOGFILE=%~dp0\%MY_FILENAME%.log
ECHO [%MY_DATETIME%] Starting operations > "%LOGFILE%"
REM Your actual script here
ECHO This is where your actual script code would go >> "%LOGFILE%"
REM Check for an error in your script
if %ERRORLEVEL% NEQ 0 (
ECHO Error encountered. Pausing for review. Error level: %ERRORLEVEL% >> "%LOGFILE%"
PAUSE
exit /b %ERRORLEVEL%
)
REM Automatically close the window after 30 seconds
timeout /t 30
ECHO Script completed successfully at %DATE% %TIME% >> "%LOGFILE%"
exit /b 0