Skip to content

Instantly share code, notes, and snippets.

@ohusq
Created May 6, 2024 20:53
Show Gist options
  • Save ohusq/b46f77676b5230725b862ea481a30a16 to your computer and use it in GitHub Desktop.
Save ohusq/b46f77676b5230725b862ea481a30a16 to your computer and use it in GitHub Desktop.
Load Visual Studio Code with cl.exe enabled, easy to use.
@echo off
setlocal
:: Path to the Visual Studio vcvars64.bat
set "VCVARS64_PATH=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
:: Check if the VC vars batch file exists
if not exist "%VCVARS64_PATH%" (
echo Error: Visual Studio 2022 Build Tools vcvars64.bat not found.
exit /b 1
)
:: Initialize Visual Studio Build Tools environment
call "%VCVARS64_PATH%" >nul 2>&1
:: Prompt user to enter the code folder path
echo Please enter the full path to your code folder:
set /p CODEFOLDER="Path: "
set "CONCAT=%USERPROFILE%\Visual Studio Code\"
:: Check if the directory exists
if not exist "%CONCAT%%CODEFOLDER%" (
echo Error: The specified folder does not exist.
exit /b 1
)
:: Change to the specified directory
cd /d "%CONCAT%%CODEFOLDER%"
:: Open Visual Studio Code in the directory
code .
:: End of script
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment