1

I want to create a Windows batch file that take the file name with particular pattern (say test*.zip ) and assign it to variable. so that I can check/validate whether the file is exists in other location or not.

How to do this ?

I tried below code.. its executing as expected but its executing twice .

@echo on

call :sub "D:\temp\test*.zip"

if exist "D:\temp\Updates\%filename%" (set flag="true") else (set flag="false")

echo %flag%

:sub
set filename=%~nx1
GOTO :EOF
1
  • Place goto :EOF on the line above :sub but it's not going to execute twice. What do you see on the console? Commented Jan 17, 2014 at 6:26

1 Answer 1

1

Unlike many languages, batch has no concept of the end of a "procedure" - it simply continues execution line-by-line until it reaches the end-of-file. Consequently, you need to goto :eof after completing the mainline, otherwise execution will continue through the subroutine code. :EOF is a predefined label understood by CMD to mean end of file. The colon is required.

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.