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
Augusto Valdivia -
Boopathi -
Augusto Valdivia -
Arun Krish -
Top comments (1)
It looks like you may be missing a
%
symbol on theif
statement. It should be written like this:Copy code
if %Monitor%==No if %Sub%==Yes dir /b /s "%Folder%">Control
In batch scripts, the
if
statement is used to check if a condition is true or false, and then execute a command based on the result. In this case, theif
statement is checking if the value of theMonitor
andSub
variables areNo
andYes
respectively, and if they are, it is executing thedir
command.However, without the
%
symbols around the variable names, theif
statement is not able to recognize the variables, and it is treating thedir
command 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 theif
statement to recognize the variables and execute thedir
command correctly.Here is an example of how the corrected code should look:
Copy code
if %Monitor%==No if %Sub%==Yes dir /b /s "%Folder%">Control
I 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.