The which command for Windows

Source: Internet
Author: User

Linux has a which command to find the location of the executable file.

For example:whichfind, which searches for the command from the path of a path variable, returns the result of the first match found.

So we can see where we are using the find program.

Windows does not have such an instruction, we can write it ourselves:

@echo Offecho%~dp$path:1@echo on

That's three lines!

Here is the result of the execution

D:\work\rf>d:\which.bat Java.exe
C:\Program files\java\jdk1.7.0_71\bin\

D:\work\rf>d:\which.bat cmd.exe

D:\work\rf>d:\which.bat cl.exe
C:\Program Files\Microsoft Visual Studio\vc98\bin\

This must write the full file name, without the extension is not possible.

Here is an extension of the batch-processing editor, which is referenced from the Windows Help file :

You can also use an edit character in a batch parameter. The editor uses the current drive and directory information to extend the batch parameter to a partial or complete file or directory name. To use the edit character, type the percent sign (%) character, followed by the tilde (~) character, and then type the appropriate editor (that is,%~modifier).

%~ $PATH: 1 searches the directory listed in the PATH environment variable and expands%1 to the fully qualified name of the first found directory. If the environment variable name is not defined or the file is not found, the editor expands to an empty string.

The which command for Windows

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.