0

I have this code which echo the variable name...

set filename=
set filename=%1 

... where %1 is a command input from cmd

However when I run this batch file again which a different input, it still has the same value as before. When I run it again, then it has the value previously entered. How do I clear the variable so when I run the program again, it receives that input rather than the one before?

1
  • Is this fragment of code by any chance contained in an IF statement or, perhaps, in a loop body? Commented Oct 15, 2012 at 17:33

2 Answers 2

2

depending on your Windows version

setlocal

might do the trick for you

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

Comments

1

I would write it like so:

@echo off
setlocal
::set filename=
set "filename=%1"
pause

That should work.

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.