- 1 year ago
How to check if a folder path matches USERs folder in BAT script
To check if a folder path matches the current user's folder (USERPROFILE), you can use the %USERPROFILE%
environment variable in a batch script. The %USERPROFILE%
variable contains the path to the current user's profile folder.
Here's an example of how you can use it in a batch script:
batch@echo off
setlocal
rem Define the folder path to check against the USERPROFILE
set "folderPath=C:\Users\JohnDoe\Documents"
rem Get the USERPROFILE environment variable
set "userProfile=%USERPROFILE%"
rem Check if the folder path matches USERPROFILE
if "%folderPath%"=="%userProfile%\Documents" (
echo The folder path matches the USERPROFILE.
) else (
echo The folder path does not match the USERPROFILE.
)
endlocal
In this example, we have set folderPath
to C:\Users\JohnDoe\Documents
. We then retrieve the value of the USERPROFILE
environment variable using %USERPROFILE%
. The if
statement then checks if the two paths are equal, and it will display a message accordingly.
Note that the %USERPROFILE%
environment variable may vary depending on the current user, so this script will match the folder path of the current user only. If you want to check against a specific user's profile, you can replace %USERPROFILE%
with the appropriate user's profile path.