Skip to content

Instantly share code, notes, and snippets.

@ravikul505
Last active July 28, 2023 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravikul505/8fa88769ac095a72252abce2c0a4dd45 to your computer and use it in GitHub Desktop.
Save ravikul505/8fa88769ac095a72252abce2c0a4dd45 to your computer and use it in GitHub Desktop.
run singular cpp file in vs code
@ECHO OFF
rem check for flags
if "%1" == "" goto noflags
rem Check if the file exists
if not exist "%~1.cpp" (
echo File "%~1.cpp" not found.
exit /b 1
)
rem check if executable exists and is up to date
if exist "exe\%~1.exe" (
echo checking for updates...
for %%F in ("%~1.cpp") do (
for %%G in ("exe\%~1.exe") do (
if %%~tF GTR %%~tG (
echo %~1.cpp was updated after the last compilation.
echo %%~tF
echo %%~tG
g++ "%~1.cpp" -g -Wall -Wextra -Werror -pedantic -o exe\%~1.exe
rem Check if compilation was successful
if errorlevel 1 (
echo Compilation failed.
exit /b 1
)
)
)
)
echo %~1.cpp is up to date.
cd exe
%~1.exe
)else (
echo %~1.cpp was never compiled.
g++ "%~1.cpp" -g -Wall -Wextra -Werror -pedantic -o exe\%~1.exe
rem Check if compilation was successful
if errorlevel 1 (
echo Compilation failed.
exit /b 1
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment