Possible to Use Label Name as a Variable?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Possible to Use Label Name as a Variable?

#1 Post by Samir » 16 Mar 2018 22:48

I have a batch file that will call to various functions where the label name is also used in the function.

For example (ALMOND in this example):

Code: Select all

:ALMOND
XCOPY \\SHARENAME\ALMOND \ALMOND /F/R/E/S/H/K/Y/D/C/L
GOTO :EOF
I wanted to know if there's any variable like %0 for the label in a batch file. Thank you in advance. 8)

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Possible to Use Label Name as a Variable?

#2 Post by Samir » 16 Mar 2018 23:10

So in reading another thread here, I ran across an example that used %~1 with call, which inspired me to try %~0 with call. Indeed, it will return the label used.

My testing batch:

Code: Select all

ECHO OFF

CALL :MAIN "TEST"
GOTO END

:MAIN
ECHO START
ECHO %~0
SET LABEL=%~0
SET LABEL=%LABEL:~1%
ECHO %LABEL%
ECHO %~1

:END
I'd love to hear feedback as I only briefly tested this. 8)

Post Reply