I am writing a Windows batch script which tries to determine if a path value (extracted from an application's config file) points to a user specific folder (e.g. %APPDATA% ) or a general one (e.g. C:\ProgramData\AppName).
The long winded way to do this would be to try and check for every possible wya this can be set, e.g this is what I started coding up:
REM Get the value from the config file, entry is "set="
set locSettingsFile="%installFolder%\setting.data"
echo "Loc file %locSettingsFile%"
IF EXIST "%locSettingsFile%" (
echo "Location settings file found at: %locSettingsFile%"
REM Got the config file,now get the set=value entry
for /F "delims=" %%a in ('FINDSTR /R /C:"^set=" %locSettingsFile%') do set "setKeyVal=%%a"
echo %setKeyVal%
IF "%setKeyVal%"=="" (
echo "Set location is not set in %locSettingsFile%"
) ELSE (
REM Got the entry now extract the value from set=value
for /f "tokens=2 delims==" %%a in ("%setKeyVal%") do set "setVal=%%a"
echo "Set value is %setVal%"
REM Now check if it points to a user specific folder
IF /I %setVal:~0,9% == "%APPDATA%" IF /I %setVal:~1,8% == ":\USERS\"(
REM Its user specific
)
)
) ELSE (
echo echo "Location settings file does not exist: %locSettingsFile%"
)
But, before I carry on with this approach, I would like to ask if there is simple one-liner that can tell me if a given pat will map to a user specific folder. Bear in mind also that on some systems the user folder could be a network UNC path.
Based only on what is certain from your question: