4

In the Windows console

  1. By where command, I'll find a file within %PATH
    e.g: where cmd -> C:\Windows\System32\cmd.exe
  2. With result above, I'll move there

I tried...

  • search in google
  • cd %(...
  • where <F> | cd

I think...

  • where command returns the directory and filename
  • So, is there any command to return just the directory?
  • and, what if it is, how to pipe which cd command
  • or, do I need a some script?
DavidPostill
  • 156,873
KEATON
  • 41

1 Answers1

5

How do I use where to cd to the directory where the command is found?

Use the following batch file (test.cmd):

@echo off
for /f %%i in ('where %1') do (
  cd /d %%~dpi
  )

Example usage:

test cmd

Further Reading

DavidPostill
  • 156,873