# Solved: Batch Label and GOTO help..



## Codiah (Sep 27, 2008)

here's my problem,

I have a batch file that has numerous commands in it set up something like this...


```
@ECHO off
COMMAND ONE
COMMAND TWO
:label
COMMAND THREE
```
is it possible to call this batch file from another batch file, but go directly to the label...

something along the lines of

*CALL myscript.bat & GOTO label*

so i can skip the first few lines of code..


----------



## Codiah (Sep 27, 2008)

Figured out a solution, if you know another way i'd still like to hear it tho...

but what i did was make some changes and use error levels..

*IF '%1'== '1' GOTO label*

so i just pass the *1* when i want to skip the beginning of the file..


----------



## TheOutcaste (Aug 8, 2007)

I've used this on occasion:


```
@Echo Off
If NOT [%1]==[] Goto :%1
Echo No label specified
GOTO :EOF
:label1
Echo label1 specified
GOTO :EOF
:label2
Echo label2 specified
GOTO :EOF
```
(Goto %1 (without the colon) works as well)
If you call the file with no parameters it will execute the first subroutine
If you specify a label, it will go to that label.
I keep a file with handy subroutines, like date and time calculations. This way I can call one from the command line or another file easily.

For subroutines that need to have parameters passed, I create a special label to use when calling them:

```
@Echo Off
If NOT [%1]==[] Goto :%1
Echo No label specified
GOTO :EOF
:label1call
Shift
:label1
Echo label1 specified
GOTO :EOF
:label2call
Shift
:label2
Echo label2 specified
GOTO :EOF
```
This way I can cut and paste the routines and don't have to re-write them. Just have to not copy the Shift command.
Another option:

```
@Echo Off
 If NOT [%1]==[] (set label=%1) & Shift & Call :%label% %*
GOTO :EOF
:label1
 Echo label1 specified
 GOTO :EOF
:label2
 Echo label2 specified
 GOTO :EOF
```
The Shift removes the label from the parameter list, and the %* passes the rest of the command line to the subroutine. If the file is called without any parameters it just returns.

HTH

Jerry


----------



## Codiah (Sep 27, 2008)

thanks again, i'll make sure to note that....


----------

