Skip to content

Instantly share code, notes, and snippets.

@okurka12
Created January 24, 2024 00:13
Show Gist options
  • Save okurka12/d91396c291466964a85a13bdd0fec6c9 to your computer and use it in GitHub Desktop.
Save okurka12/d91396c291466964a85a13bdd0fec6c9 to your computer and use it in GitHub Desktop.
Creates a snapshot of a file.
@echo off
setlocal enabledelayedexpansion
rem
rem Usage: .\snap.bat
rem
rem Upon invocation, copies `name.ext` to `name_1.ext`.
rem If `name_1.ext` already exists, copies to `name_2.ext`,
rem then `name_3.ext` and so on...
rem
set "name=ipt_tahak"
set "extension=svg"
set "sourceFile=%name%.%extension%"
rem Check if source file exists
if not exist "%sourceFile%" (
echo Source file not found: %sourceFile%
exit /b
)
rem Find the next available snapshot index
set "index=1"
:findNextIndex
set "snapshotFile=%name%_%index%.%extension%"
if exist "%snapshotFile%" (
set /a "index+=1"
goto :findNextIndex
)
rem Copy the source file to the snapshot file
copy "%sourceFile%" "%snapshotFile%"
echo Snapshot created at %DATE% %TIME%: %snapshotFile%
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment