If I do a command like (on windows cmd.exe):

where dir


where cd

I get the following message:

INFO: Could not find files for the given pattern(s).

This tends to mean to me that cd and dir are not actual programs, but are built in to cmd.exe.

Now the real question is:

Is there ant way to replace cd and dir with other programs? If you wanted to replace say more, you could just put another program by that name in the system PATH in front of where more is.

But you cannot do that with cd and dir. Am I just stuck with them?

  • Except for doskey you probably cannot do it normally because AFAIK the command processor checks against its hardcoded list of builtin commands before trying anything else. If you really need it, you could potentially resort to hacking hex-edit cmd.exe and replace builtin commands with glibberish, or intercept your keyboard input before cmd.exe gets it (won't work with batch files), or implementing a cmd.exe wrapper altogether. Does that count? What do you need to replace the builtins for, anyway? – Jack White Jul 19 '16 at 16:51

Is there any way to replace cd and dir with other programs?

No, but you can come close - here's how:

  1. You can create a batch file called dir.cmd.

    @echo off
    echo I have replaced dir


    I have replaced dir

    However you have to call it by its full name dir.cmd not just dir, unless…

  2. You can use doskey to redefine dir:

    doskey dir=dir.cmd


    I have replaced dir
  • I was hoping I would not have to resort to doskey....it has a lot of quirks – DarthRubik Jul 19 '16 at 1:35
  • @DarthRubik Really? – DavidPostill Jul 19 '16 at 1:37
  • Yes...a doskey macro cannot be used on either side of a pipe (which is annoying)....and that's just for starters – DarthRubik Jul 19 '16 at 1:40
  • Example: doskey d=dir & d > out.txt does not create a new file called out.txt. It prints to the console instead – DarthRubik Jul 19 '16 at 1:58
  • 1
    ISTM that the first line of your answer should say, "No, but you can come close; here's how...". – Scott Jul 19 '16 at 5:34

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.