Nitrodbz
Nitrodbz

Reputation: 1286

Batch file variable

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?

Upvotes: 0

Views: 2016

Answers (2)

djangofan
djangofan

Reputation: 29669

I would write it like so:

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

That should work.

Upvotes: 1

Wolfgang Fahl
Wolfgang Fahl

Reputation: 15769

depending on your Windows version

setlocal

might do the trick for you

Upvotes: 2

Related Questions