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]

st: Path to current .do file?


From   "James Beard" <[email protected]>
To   [email protected]
Subject   st: Path to current .do file?
Date   Thu, 18 Jul 2013 01:00:01 -0000

Dear Statalisters,

In a Stata .do file (I'm using Stata 12 on Windows) is it possible to 
find out the path to the currently executing .do file?

I'm currently setting up some rather complicated data management in 
Stata, which will eventually have to deal with tens of thousands of 
files. Normally, I would put everything in the same folder, but in 
this case, that would become unmanageable. So, I have different 
folders for different sets of files. And I want to use relative paths 
to access them. If I was going to be running my .do files myself, I 
would just know that I have to start in the right place, but I can't 
guarantee that the people who will run them will do that. And I don't 
want to hard-wire paths in my .do files because the drive letters and 
paths to the "root" of my folder structure on the "production" system 
will be different from the root on my development system. So within 
each .do file, I want to -cd- to the folder in which each .do file is 
located, so the .do file can reliable locate files in other folders. 
With apologies to non-Windows users, you can do this sort of thing 
with "DOS" batch files, with -cd/d %~dp0-, so I could provide a .bat 
file wrapper for each of my .do files, but this isn't an ideal 
solution, and wouldn't actually stop someone running one of my .do 
files directly from the wrong folder.

Thanks in advance.

*
*   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