Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Capturing the directory of a .do file


From   Phil Schumm <[email protected]>
To   [email protected]
Subject   Re: st: Capturing the directory of a .do file
Date   Fri, 7 Sep 2007 05:36:01 -0500

On Sep 7, 2007, at 4:39 AM, Sergiy Radyakin wrote:
2Austin: Why not just use relative paths, and have folks run the do- file in the relevant starting directory? Because when a .do file is run, current directory is not necessarily the directory where the .do file is located.

True, but you can check for that, at least partially. In particular, you can use -confirm file- to verify that the various files on which your do-file depend(s) are in the expected locations relative to the current working directory.

Given the original question, I think Austin's suggestion was spot on (including the bit about the path separators, which should always be specified using -c(dirsep)- to make sure that your code works cross- platform). IOW, write all your code using paths relative to the project's root directory, and then specify in the README that users should -cd- to the project directory before running it. As long as you distribute (or move) the entire project directory, you'll be fine.

Note that, for those with Unix experience, this is quite natural. If I download a program and want to compile it, I would typically need to -cd- to the root of the distribution before compiling, and I would expect the Makefile to refer to all files distributed with the source by their relative paths (so that I am free to compile wherever I want on my system).

Of course, if you want users to be able to double-click or use menu's to execute do-files, then things become a bit more complicated, and the ability for a do-file to "know it's location" becomes important. However, we're talking about Stata here -- what do you need the GUI for? ;)


-- Phil

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index