Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Relative directory paths in Stata?


From   Robert Picard <[email protected]>
To   [email protected]
Subject   Re: st: Relative directory paths in Stata?
Date   Tue, 6 Aug 2013 12:12:15 -0400

The problem with getting the path to the current do-file or to the
directory that contains it is that there can be more than one
currently running do-file. If -do a.do- is placed inside "b.do", which
itself is called by "d.do" using -do b.do-, then all 4 do-files can be
running at the same time.

I have solved this issue with -project-, which was mentioned in a recent thread:

http://www.stata.com/statalist/archive/2013-07/msg00664.html



On Tue, Aug 6, 2013 at 11:53 AM, Allan Reese (Cefas)
<[email protected]> wrote:
> This little program godir.ado may be useful. Copy it to your personal ado directory.
> Use File/Recent menu to open a datafile in your working directory, and store do files relevant to that data in the same directory.
> On the do file editor, I commented long ago that the menu or button force it to open with a blank file, then you can open recent ones.
>
> GODIR.ADO
> program godir
>   version 8
>   if strpos(reverse("$S_FN"),"/") {
>      local lastslash = length("$S_FN")-strpos(reverse("$S_FN"),"/")
>    }
>    else {
>      local lastslash = length("$S_FN")-strpos(reverse("$S_FN"),"\")
>    }
>   local target = substr("$S_FN", 1,`lastslash')
>   if strpos("`target'", ".dta") local target= "`c(pwd)'"
>   cd "`target'"
>   end
>
> and its hlp file:
>
> GODIR.HLP
> {smcl}
> {* 10sep2001/3nov2004/5oct2007/18dec2009}{...}
> {hline}
> {cmd:help godir}
> {hline}
>
> {title:Title}
>
> {p 4 4 2}{hi:godir} {hline 2} cd to the directory containing the current dataset
>
>
> {title:Syntax}
>
> {p 8 17 2}
> {cmd:godir}
>
>
> {title:Remarks}
>
> {p 4 4 2} Intended to be used when a "recent dataset" has been opened from the file menu.
> Saves re-typing the path.
>
>
> {title:Options}
>
> {p 4 8 2}There are no parameters or options
>
> {title:Acknowledgement}Dan Blanchette  of University of North Carolina provided very helpful advice.
>
> {title:Author}
>
> {p 4 4 2}R Allan Reese{break}
> Cefas, Weymouth, U.K.{break}
> [email protected]
> -------------------------------------------------------------------------
>
>
>
> Date: Mon, 5 Aug 2013 09:49:38 +0200
> From: Mark Millstone <[email protected]>
> Subject: st: Relative directory paths in Stata?
>
> Hi all,
>
> There's one thing I was never able to figure out in Stata. How can I
> instruct the programme to change to the directory which contains the
> current do-file? For instance, if I use a USB stick, depending on the
> computer, I may be working in drive "E:\My files" or "F:\My files".
> Now, if I change the working directory to "F:\My files" in the former,
> or "E:\My files" in the latter case, I will get an error. Can't I just
> instruct
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index