Last active
July 28, 2023 04:12
-
-
Save ravikul505/8fa88769ac095a72252abce2c0a4dd45 to your computer and use it in GitHub Desktop.
run singular cpp file in vs code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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