Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: limitation of -filefilter-


From   Phil Schumm <pschumm@uchicago.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: limitation of -filefilter-
Date   Tue, 23 Nov 2004 09:24:56 -0600

At 8:53 AM -0600 11/23/04, Kevin Turner wrote:
 >. filefilter foo\$bar.txt foo\$bar2.txt, f("a") t("b")
varlist not allowed
r(101);

where the "\" is (presumably) needed to escape the "$", thus
preventing macro expansion.
Yes, the slash does prevent macro expansion. The reason that a single backslash
doesn't work here lies in the fact that there is already a backslash preceding
the file name. When the first pair of backslashes is encountered, they collapse
down to a single backslash (there is a backslash escaping a backslash). The
next character to be parsed is the dollar sign, which now has no preceding
backslash since the previous two were already parsed. The necessary solution
requires three backslashes for the Stata parser to correctly interpret the
path. Thus, a correct path would look like:

. filefilter "foo\\\$bar.txt" "foo\\\$bar2.txt", f("a") t("b")

This issue involving escape characters and macro expansion is, unfortunately,
one that you could encounter with any Stata command, not just -filefilter-.

Kevin,

Thanks very much for the clarification, and for the trick with the quotes (I'm busy using them right now!). Actually, I was already aware that backslash escapes a backslash, and am used to using constructions of the form "\\\$" or "\\\\\\\$" (that's 7 backslashes, necessary when there is an intevening macro which then needs to expand to "\\\$").

What I still don't understand, though, is where is the second backslash you are referring to in this case? For example, when reading a file named foo$bar.dta:


. use foo\$bar


works, but:


. use foo\\\$bar
file foo\$bar.dta not found
r(601);

does not. Is it perhaps that the first two arguments to -filefilter- are being read into macros, which when they are used expand from things like "foo\\\$bar" to "foo\$bar"? And is the reason that the argument to -save- doesn't require the three backslashes that this is never read into a macro that is then expanded?

Thanks,


-- 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index