2

This question is interesting because normally I would use where.exe on Windows to find the path to a program on my path. However, where has an option dir, /r to recursively search a path. I don't know if there is a pattern or option for where to properly interpolate for dir or what? It returns INFO: Could not find files for the given pattern(s).. I wonder if dir is built into a dll or something somewhere? Anyways, I have no idea where dir is. I have a different dir.exe program from MinGW C:\MinGW\msys\1.0\bin\dir.exe. That is not the native Windows dir program though.

Several PowerShell one-liners only return emptiness.

PS> (Get-Command dir).Source

PS> Get-Command -Name dir

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           dir -> Get-ChildItem

https://stackoverflow.com/questions/62270559/where-is-programs-path-for-powershell-command

I also wonder if the location is hidden for security purposes or if dir is merely so ancient and insignificant it's just in memory or something?

1
  • 1
    In MS-DOS it was an internal command in COMMAND.COM and I always assumed it was the same with CMD.EXE in Windows. Aug 17 at 11:38

2 Answers 2

2

What is the path to the dir program?

It doesn't have one.

dir is one of several commands that are internal to the cmd shell.

The full list can be found at Internal commands - Windows CMD - SS64.com and includes:

ASSOC, BREAK, CALL ,CD/CHDIR, CLS, COLOR, COPY, DATE, DEL, DIR, DPATH, ECHO, ENDLOCAL, ERASE, EXIT, FOR, FTYPE, GOTO, IF, KEYS, MD/MKDIR, MKLINK (vista and above), MOVE, PATH, PAUSE, POPD, PROMPT, PUSHD, REM, REN/RENAME, RD/RMDIR, SET, SETLOCAL, SHIFT, START, TIME, TITLE, TYPE, VER, VERIFY, VOL

...

It is possible for a system to have an internal command and an external command with the same name. If you have a command called DATE.exe and want to run that in preference to the internal DATE command, use the full pathname to the file e.g. C:\utils\date.exe even if your current directory is C:\utils\.

So in your case you can run the MingW version of dir by using the full path C:\MinGW\msys\1.0\bin\dir.exe or by running a MingW terminal instead of cmd (then dir will run the MingW version).

Note that, as you have noticed, PowerShell has defined a dir alias so that users can run a "dir" command in PowerShell.

I also wonder if the location is hidden for security purposes or if dir is merely so ancient and insignificant it's just in memory or something?

It is essentially in memory, but only when a cmd shell is loaded and then can be accessed by typing dir. The same applies to all of the other internal commands.

1
  • Thank you, the reference provided is very concise. Aug 17 at 12:26
0

Apparently dir (among many others) is built-into cmd.exe.

The command is usually implemented as an internal command in the command-line interpreter (shell).

https://en.wikipedia.org/wiki/Dir_(command)

COMMAND.COM is the default command-line interpreter for MS-DOS, Windows 95, Windows 98 and Windows Me. In the case of DOS, it is the default user interface as well. It has an additional role as the usual first program run after boot (init process), hence being responsible for setting up the system by running the AUTOEXEC.BAT configuration file, and being the ancestor of all processes.

https://en.wikipedia.org/wiki/COMMAND.COM

Command Prompt, also known as cmd.exe or cmd, is the default command-line interpreter for the OS/2,[1] eComStation, ArcaOS, Microsoft Windows (Windows NT family and Windows CE family), and ReactOS[2] operating systems.

https://en.wikipedia.org/wiki/Cmd.exe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.