我正在编写一个Windows批处理脚本,该脚本尝试确定路径值(从应用程序的配置文件中提取)是指向用户特定的文件夹(例如%APPDATA%)还是指向常规文件夹(例如C:\ ProgramData\AppName)。
要做到这一点,冗长的方法是尝试检查每个可能设置的wya,例如这是我开始编写的代码:
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%"
)
但是,在我继续使用这种方法之前,我想问一下是否有一个简单的行程序可以告诉我给定的pat是否会映射到用户特定的文件夹。还要记住,在某些系统上,用户文件夹可能是网络UNC路径。