A Windows command-line program that changes the current directory to whatever directory the topmost Explorer window is looking at.
In other words, it is the reverse of the many "Open Command Window Here" tricks that exist for various versions of Windows. Instead of opening a new command window for each directory in which you want to do work, you move the current directory in an existing console to where you want it to be.
- Download https://github.com/eteeselink/cdhere/raw/master/Downloads/cdhere-1.4.zip and unzip it somewhere convenient.
- Run
addToPath.cmd
with administrator priviledges to add the directory to your PATH, so that you can accescdhere
from anywhere.
cdhere
Which looks like:
C:\Users\teeselinke>cdhere
D:\hobby\cdhere\cdhere\src>
Add a /d
for an interactive version of plain cdhere
. Usage is simple:
cdhere /d
This will open a "Browse to folder" dialog, and your command-line window will change the current directory to the selected folder.
If you use Bash on Windows (e.g. through msys of cygwin), ozh recommends you add the following to your ~/.bash_profile
:
function cdhere {
CDWHERE=$(c:/path/to/cdhere/cdwhere.exe)
if [ "$CDWHERE" != "" ]; then
cd $CDWHERE
fi
}
Windows processes cannot change the directory of their parent process, but
batch files can. Therefore, cdhere
consists of two files, a C++ program
called cdwhere.exe
which finds the topmost Explorer window and queries it
for its current directory, and cdhere.cmd
, which uses cdwhere.exe
's
output to actually change the directory.
Please report bugs using GitHub's issue tracker at https://github.com/eteeselink/cdhere/issues
The only not-entirely-trivial bit of this code is the part that asks an Explorer window where it's pointed. This, however, is something that Raymond Chen (of The Old New Thing fame) already worked out for me [back in 2004] 6. Much of the code you see here is little more than his example refactored.
The /d
switch was contributed by Danyil Bohdan