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 295943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:30:12+00:00 2026-05-12T06:30:12+00:00

So I recently stumbled on the (potentially) useful %~$PATH:1 expansion, however I seem to

  • 0

So I recently stumbled on the (potentially) useful %~$PATH:1 expansion, however I seem to be unable to make it work correctly. I tried to use it to make a cheap Windows version of the which command, however the syntax seems to be defeating me. My batch file looks like this:

@echo off
echo %~$PATH:1

However when I run this with for example

which cmd

all I get as output of “ECHO is off.”, which means according to the docs that the %~$PATH:1 didn’t find “cmd”. What am I doing wrong?

  • 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-05-12T06:30:12+00:00Added an answer on May 12, 2026 at 6:30 am

    Checking for files with the extensions .exe, .cmd or .bat is not enough. The set of applicable extensions is defined in the environment variable PATHEXT.

    Here is my version of a which command that honors the PATHEXT variable upon search:

    @echo off
    rem Windows equivalent of Unix which command
    
    setlocal enabledelayedexpansion
    
    if "%~1"=="" (
        echo Usage: which cmdname
        exit /b 1
    )
    
    call :findOnPath "%~1"
    if not errorlevel 1 exit /b 0
    for %%E in (%PATHEXT:;= %) do (
        call :findOnPath "%~1%%E"
        if not errorlevel 1 exit /b 0
    )
    
    echo "%~1" not found on PATH.
    exit /b 1
    
    :findOnPath
        if not "%~$PATH:1" == "" (
            echo "%~$PATH:1"
            exit /b 0
        )
        exit /b 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently stumbled across the ability to use boomarks in Visual Studio. ( http://www.codeproject.com/Articles/42973/Using-Bookmark-in-Visual-Studio.aspx
Recently, I have stumbled upon the basic understanding about PKI work-in-action process. I have
I recently stumbled upon Play framework while evaluating frameworks to use in a project.
I recently stumbled across an article that claims Microsoft is banning the memcpy() function
we recently stumbled over a behaviour of NHibernate that gave us a real headache
I have recently stumbled upon a problem with selecting relationship details from a 1
I've recently stumbled over this expression: True == False in (False,) It evaluates to
I recently started looking into building web applications using .NET MVC and I stumbled
I recently stumbled upon a global hotkey class ( This one ), it works
I recently stumbled across DBslayer ( http://code.nytimes.com/projects/dbslayer/wiki/WhyUseIt ) and wondered what is the actual

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.