Selfmodifying .bat

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
miskox
Posts: 609
Joined: 28 Jun 2010 03:46

Selfmodifying .bat

#1 Post by miskox » 15 Jul 2024 11:52

I needed an information when .bat file was run - so I kept this information in a seperate file. But then I thought it would be better to have this information in the .bat file itself as the last line (because there are no other files I need). So this would not be too hard to implement. So here it is:

Code: Select all

@echo off
copy /y %~f0 *.backup 
findstr /B /V /C:"LLLLL#" %~f0 >tmp.tmp&echo LLLLL#Last run was at: %date% %time% %username%#>>tmp.tmp&move tmp.tmp %~f0 >nul
fc %~n0.backup %~f0
goto :EOF

LLLLL#Last run was at: pon. 15. 07. 2024 19:49:23,88 saso#
Differences:

Code: Select all

Comparing files test.backup and C:\TEMP\TEST.CMD
***** test.backup

LLLLL#Last run was at: pon. 15. 07. 2024 19:49:23,88 saso#
***** C:\TEMP\TEST.CMD

LLLLL#Last run was at: pon. 15. 07. 2024 19:50:28,52 saso#
*****
Saso

Post Reply