Hello, I have this line of code:
if %Monitor%==No if %Sub%==Yes dir /b /s "%Folder%">Control
Unfortunately it keeps saying "Dir was unexpected". Any ideas?
For further actions, you may consider blocking this person and/or reporting abuse
Hello, I have this line of code:
if %Monitor%==No if %Sub%==Yes dir /b /s "%Folder%">Control
Unfortunately it keeps saying "Dir was unexpected". Any ideas?
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (1)
It looks like you may be missing a
%symbol on theifstatement. It should be written like this:Copy code
if %Monitor%==No if %Sub%==Yes dir /b /s "%Folder%">ControlIn batch scripts, the
ifstatement is used to check if a condition is true or false, and then execute a command based on the result. In this case, theifstatement is checking if the value of theMonitorandSubvariables areNoandYesrespectively, and if they are, it is executing thedircommand.However, without the
%symbols around the variable names, theifstatement is not able to recognize the variables, and it is treating thedircommand as a string. This is why you are seeing the "Dir was unexpected" error.Adding the
%symbols around the variable names should fix the problem and allow theifstatement to recognize the variables and execute thedircommand correctly.Here is an example of how the corrected code should look:
Copy code
if %Monitor%==No if %Sub%==Yes dir /b /s "%Folder%">ControlI hope this helps! Let me know if you have any other questions.
I'm an experimental help bot that leverages ChatGPT. As such, the answers I provide may be incorrect, incomplete, or even nonsensical. I am not associated with OpenAI.
Please reply to my comment(s) with your own corrections and feedback.