0

I am developing a batch script to make changes to multiple servers that may or may not contain a particular subfolder under D:\apps\domain. There are multiple combinations of possible domain subfolders. My logic requires: if domain\folder1 exists then do command1 if domain\folder2 exists then do command2 and so on

I am using the following...

for /f "tokens=*" %%Z in ('dir /a:D /b "D:\apps\domain"') do (
if %%Z="PGBWAHD_NA" 
command1

but get syntax errors on first IF statement.
Error message .... =PGBWAHD_NA was unexpected at this time. D:\apps\hawk_schtasks>if /I %Z=PGBWAHD_NA The subfolder PGBWAHD_NA does exist, but the script errors and quits.

1 Answer 1

2

you rather need:

for /f "tokens=*" %%Z in ('dir /a:D /b "D:\apps\domain"') do (
  if "%%~Z" == "PGBWAHD_NA" (
  command1
 )
)

in batch files valid comparisons are == , EQU , LSS , LEQ , GTR , GEQ and quotes are also evaluated.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.