*! version 1.0 2014-11-01

Title

pathof -- Return the absolute path of any parent directory of the current working directory.

Syntax

pathof
[parent directory]
[, local(macname)]

Description

pathof searches the path of the current working directory for the specified parent directory.
The path to the parent directory is returned in r() and in the local macro, if specified.

Options

local(macname) inserts the path to the parent directory in
local macro macname within the calling program's space. Hence,
that macro will be accessible after pathof has finished.
This is helpful for subsequent use to specify absolute paths within the parent directory.

Remarks

pathof is useful when a project is contained in a parent directory, and that parent
directory may change locations. Absolute file paths in a do-file can be specified using
the returned values from pathof. These values will be updated when the do-file
is run again from a new location.

For example, a single parent folder named "thesis" may have subfolders "original" and
"final". Do-files anywhere within the "thesis" parent directory can reference
these locations as follows:

. pathof thesis , local(thesis_dir)

. use "`thesis_dir'/original/mydata.dta"

. save "`thesis_dir'/final/myfinaldata.dta"

The thesis parent directory can then be moved or shared, and the path names will update
to the new location. Another useful application is a project that is stored in a Dropbox
or Google Drive folder that is accessed from multiple computers.

Note, the path of the current working directory is searched to find the specified parent directory.
The working directory must be somewhere within the parent directory when the command is run.

If parent directory is not specified, the root directory is returned.

If parent directory is not found in the current working directory, the program exits
with a warning. No changes are made to local(macname) in this case.

Examples

. pathof , local(root)

. display "`root'"

. pathof Users

. display "`r(path)'"

. pathof Dropbox, local(dropbox)

. display "`r(path)'"

. display "`dropbox'"

. pathof "Google Drive", local(gdrive)

. display "`r(path)'"

. display "`gdrive'"

Saved results

pathof saves the following in r():

Macros

r(path) Path of parent directory

Author

Michael Barker

Georgetown University

mdb96@georgetown.edu

https://github.com/michaelbarker/stata-pathof

Also see

findit dropbox

findit project