Statalist


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

Re: st: I can't get fs to work from inside a do file


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: I can't get fs to work from inside a do file
Date   Sun, 17 Feb 2008 00:34:39 +0900

Gabi Huiber wrote:

Nick Cox has this little command called fs, which reads the files in a
certain folder and remembers them in r(files). I tried to use it to
run a bunch of do-files from inside a root do-file, because the name
and number of these subsequent do-files can vary between the
sub-folders of interest. So here's what I did:

[redacted]
. fs prototype/${paper}/*.do
> local dofiles=r(files)
>
> foreach k of local dofiles {
> do "prototype/${paper}/`k'"
> }
>
> clear
> di "goodbye"

As you can see, Stata breezes right through the lines after fs. It
also does not interpret fs: display r(files) shows nothing. However, I
can copy the fs line from the results window and paste it in the
command window, and it will execute just fine. Ditto for all the lines
below it.

Any ideas?

--------------------------------------------------------------------------------

Do you see the files displayed in the Review window when the -fs- command
executes?  If not, then -fs- isn't seeing any do-files in the directory that
you specify, and might not even be directed correctly to the directory at
all.  I tend to have trouble with -fs- querying a directory that's not
current, so I just change directories in the do-file to make the target
directory current, and then change back afterward.

Also, avoid evaluating the returned macro;  you'll truncate the list to 244
characters, and might also mess up the compound quotes.

Try something like the following instead:

cd prototype/${paper}/
fs *.do
foreach k of local `r(files)' {
    do "`k'"
}
. . .
cd <original directory>

Joseph Coveney



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