Using filename in variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
karaziki
Posts: 22
Joined: 28 Nov 2014 22:16

Using filename in variable

#1 Post by karaziki » 13 Mar 2015 19:45

I was thinking it will be easy but become a headache
I'm trying to set a variable contains filename like;

Code: Select all

SET %~n1_var=(%~z1)
or
SET /a %~n1_var=(%~z1)

But when it comes to call back, even I couldn't test is it set or not like;

Code: Select all

ECHO "%%~n1_var%"
or
ECHO "%~n1_var%"

I tried many combinations (like an idiot) but none of them work.
Is there a way to handle it?

All bests
Evren

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Using filename in variable

#2 Post by Squashman » 13 Mar 2015 20:09

Try using delayed expansion.

karaziki
Posts: 22
Joined: 28 Nov 2014 22:16

Re: Using filename in variable

#3 Post by karaziki » 13 Mar 2015 20:35

Ah yess, thank you
It respond in echo as expected. Time to integrate.

All Bests

Post Reply