GitHunt
ET

eteeselink/cdhere

Change the current console directory to wherever you're looking at in Windows Explorer

CDHERE

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.

Installation

Usage

cdhere

Which looks like:

C:\Users\teeselinke>cdhere
D:\hobby\cdhere\cdhere\src>

Interactive mode

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.

Usage from Bash

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
}

Background

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.

Bugs

Please report bugs using GitHub's issue tracker at
https://github.com/eteeselink/cdhere/issues

Acknowledgements

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

License

zlib license

Contributors

zlib License
Created March 26, 2013
Updated October 16, 2023