Reputation: 5354
I want to check if the user is in the correct directory in the command prompt using a Windows batch file. The correct directory is stored in a system environment variable. For example, if HOME
is set to C:\path\to\home
, I want to know if the user is in that directory:
c:\some\directory>check.bat
No
c:\path\to\home>check.bat
Yes
Upvotes: 2
Views: 244
Reputation: 11367
You can compare the location the script in being run from with a check like this
if /i "%~dp0"=="%HOME%\"
Or check the current working directory with %CD%
However, you could also just make it the correct directory
cd /d "%HOME%"
For a true directory comparison where folders may or may not have a trailing backslash
for %%A in ("%~dp0%\") do for %%B in ("%HOME%\") do if /i "%%~fA"=="%%~fB"
Upvotes: 2
Reputation: 8773
if /i "%CD%"=="%HOME%" echo woooooooooo!
%CD% represents the current directory for the command prompt.
Upvotes: 2