I have the following code snippet:
@echo off
for %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist "%%d:\Program Files (x86)\location\folder" (
cd /d "%%d:\Program Files (x86)\location\folder"
) else cd /d "%%d:\location\folder\" 2>nul && goto :break
)
::display error message if folder not found
:break
if %errorlevel% equ 0 (
echo "Folder found, going to folder location"
) else (
set /p location=Could not find folder. Please enter folder location:
cd %location%
echo %location%
)
For some reason, when I give it location to CD to, the first time it CDs to the wrong file location. If I run the code snippet again from the same command line, it CDs to the previously given file location. Any reason this could be?