I'm writing a script to open folders that our devs commonly access all the time at work both through the command line and through explorer. Right now this is what it looks like:
@echo off
if "%~1" == "" goto noargs
if "%~1" == "/h" goto noargs
if "%~1" == "common1" goto setcommon1
if "%~1" == "common2" goto setcommon2
REM other folders here...
if "%~2" == "-t" (
set OPENINCMD=1
) else (
set OPENINCMD=0
)
REM This is where noargs is but I removed it for brevity
:setcommon1
set FOLDERPATH="C:\Users\username\common folder 1"
goto execute
:setcommon2
set FOLDERPATH="C:\Users\username\CommonFolder2"
goto execute
:execute
if %OPENINCMD% EQU 1 (
cd %FOLDERPATH%
) ELSE (
explorer.exe %FOLDERPATH%
)
But I would like to be able to set the %FOLDERPATH% variable as I'm parsing through the command line arguments at the start.
I have tried using setlocal enableextentsions enabledelayedexpansion and using !FOLDERPATH! instead of %FOLDERPATH% while executing and also in place of FOLDERPATH while setting the variable. I have also tried using !FOLDERPATH! in both places with no luck. I have endlocal at the end of my file as well.
This is what I envision it looking like but this doesn't set the FOLDERPATH variable when run.
...
if "%~1" == "" goto noargs
if "%~1" == "/h" goto noargs
if "%~1" == "common1" set FOLDERPATH="C:\Users\username\common folder 1"
if "%~1" == "common2" set FOLDERPATH="C:\Users\username\CommonFolder2"
...
What am I missing?