Title

cdl -- Change working directory, and project directory

Syntax

cdl [path_el | < | data] [, project]

Description

cdl displays the current working directory, or changes it and adds it to the recent list. When the project option is specified, cdl does the same thing for the current project directory.
The recent list is remembered across Stata sessions, and is specific to each instance id.

o- With no main parameter, cdl displays the current working directory.

o- path_el explicitly specifies the directory to change to.

o- < specifies switching back to the prior working directory.

o- data specifies switching to the directory of the current data source.

If you have a path that conflicts with some other part of the command, you can either prefix your path with ./ (ie, current directory) and/or enclose it in quotes.

On Startup

Because recent settings are remembered across stata sessions, you can automatically start a new Stata session in your last used directory by including the appropriate command in profile.do.

My recommendation for that command would be elfs startup, run, which can set the startup directory and more, and which can help insulate you and your profile.do file from future syntax changes.
However, in principal, cdl or cdl, p in profile.do would also work.

Project Directories

A project directory is one directly containing a file named project settings.do.

When you specify the project option, cdl will change the current project directory to the (new) current working directory or its nearest parent that is a project directory.
If you specify project for a directory that has no parent project directory, the current project directory is cleared -- set to empty.

recent project directories are tracked independently of recent working directories.

Project Settings

Whenever cdl changes the project directory - including to or from empty - it runs a do-file or two:

o- If the project directory being changed from contains a file named project settings off.do, that file will be run first.

o- Then, in the project directory being changed to, project settings.do is run. That file exists by definition, though it can be empty.

projdo offers a bit of a shortcut for creating or running these files.

Remarks

cdl tracks its current/recent working directories independently from the one built-in to Stata, so the two can get out of sync -- for example, if you use cd to change Stata's working directory.
Whenever cdl is invoked, though, it leaves the two in sync.
In the rest of this help file, then, 'current working directory' refers unambiguously to both.

Examples

. cdl a space filled name

. cdl data to switch to the directory of the data in memory

. cdl < to return to the previous working directory