# Back to Work with a Push and a Pop

Jiro's pick this week is pushd & popd by Peter Bodin.

Navigating through folders is a big part of my MATLAB workflow, especially because I may be working on multiple demos/projects at any one time. When I change folders, invariably I may want to come back to where I was.

### Example

Here's an example illustrating my workflow. I'll use pushd and popd to help me do this.

I'm currently working on this blog post. I am located here:

pwd
ans =
C:\MyStuff\Work\NoCopy\Blog\POTW\PushPop


I just got a call from Bob and Brett saying that they need an updated version of the GUI Building demo ASAP. Time to switch folders!

% works like CD
pushd C:\MyStuff\Work\Demos2009b\GUIBuilding
pwd
ans =
C:\MyStuff\Work\Demos2009b\GUIBuilding


I realize that I am missing a couple of key files for this demo. Well, that's understandable. I haven't ported over the files from my master version. I'm not quite sure which files I need, so let me go check.

pushd ..\..\Demos_public\GUIBuilding
pwd
ans =
C:\MyStuff\Work\Demos_public\GUIBuilding


I find out that I need two files: "myFilter.m" and "myPSD.m". Let me capture this folder name.

copyFromFolder = pwd;

I go back to my R2009b demos folder and copy over the two files.

popd
pwd
copyfile(fullfile(copyFromFolder, 'myFilter.m'));
copyfile(fullfile(copyFromFolder, 'myPSD.m'));
ans =
C:\MyStuff\Work\Demos2009b\GUIBuilding


Now, I can zip this up and email it to Bob and Brett.

zip('GUIDemo.zip', ...
{'filteringGUI.fig', 'filteringGUI.m', ...
'myFilter.m', 'myPSD.m', 'myImportfile.m'});

% I'm commenting this part out so that it won't keep sending email to my
% buddies every time I publish this script.
%
%   sendmail({'Robert.Bemis@mathworks.com', 'Brett.Shoelson@mathworks.com'}, ...
%     'GUI Building Demo', 'Hi Bob and Brett, here it is!', 'GUIDemo.zip');

Now, I'm ready to get back to my blog post! Ta-dah!

popd
pwd
ans =
C:\MyStuff\Work\NoCopy\Blog\POTW\PushPop


Another nice feature of pushd is that you can pass in any file that is on the MATLAB path, and it will go to that directory. For example, I know that there is an AVI called "rhinos.avi", which is one of the demo files from the Image Processing Toolbox. I want to see the other demo files from that toolbox.

pushd rhinos.avi
pwd

% go back
popd
ans =
C:\Program Files\MATLAB\R2009b\toolbox\images\imdemos


### Interactive Alternative

If you'd rather click your way through, we have that built-in to the Current Folder Browser.

Notice the Back and Forward buttons to "pop" back to where you were. Ken and Mike blogged about it here.