Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:51:56+00:00 2026-06-03T19:51:56+00:00

I have a simple function written to check for directories: :direxist if not exist

  • 0

I have a simple function written to check for directories:

:direxist
if not exist %~1 (
    echo %~1 could not be found, check to make sure your location is correct.
    goto:end
    ) else (
    echo %~1 is a real directory
    goto:eof
    )

:end is written as

:end
endlocal

I don’t understand why the program would not stop after goto:end has been called. I have another function that uses the same method to stop the program and it work fine.

:PRINT_USAGE
echo Usage:
echo ------
echo <file usage information>
goto:end

In this instance, the program is stopped after calling :end; why would this not work in :direxist? Thank you for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:52:00+00:00Added an answer on June 3, 2026 at 7:52 pm

    I suppose you are mixing call and goto statements here.

    A label in a batch file can be used with a call or a goto, but the behaviour is different.
    If you call such a function it will return when the function reached the end of the file or an explicit exit /b or goto :eof (like your goto :end).

    Therefore you can’t cancel your batch if you use a label as a function.

    However, goto to a label, will not return to the caller.

    Using a synatx error:

    But there is also a way to exit the batch from a function.
    You can create a syntax error, this forces the batch to stop.
    But it has the side effect, that the local (setlocal) variables will not be removed.

    @echo off
    call :label hello
    call :label stop
    echo Never returns
    exit /b
    
    :label
    echo %1
    if "%1"=="stop" goto :halt
    exit /b
    
    :halt
    call :haltHelper 2> nul
    
    :haltHelper
    () 
    exit /b
    

    Using CTRL-C:

    Creating an errorcode similar to the CTRL-C errorcode stops also the batch processing.
    After the exit, the setlocal state is clean!
    See @dbenham’s answer Exit batch script from inside a function

    Using advanced exception handling:

    This is the most powerful solutions, as it’s able to remove an arbitrary amount of stack levels, it can be used to exit only the current batch file and also to show the stack trace.
    It uses the fact, that (goto), without arguments, removes one element from the stack.
    See Does Windows batch support exception handling?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a very simple function: function editCategory() { $ID = urlencode($_GET['id']); $cname
I have written a simple jQuery.ajax function which loads a user control from the
I have simple from written on C/gtk+ and i have function in this appliction.
I have written a simple function: function inputChanged() { $('input').change(function(){ $(this).addClass('changed'); }); } I
I have a simple function written in Oracle 9i (version 9.2.0.4.0) to simulate an
I'm sure i've badly written this. I have a simple form which you enters
I have a simple function in which an array is declared with size depending
I have a simple function that I want to call in the code behind
I have a simple function to open an editor: open_an_editor() { nano $1 }
I have a simple function that returns an NSString after decoding it. I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.