Statalist The Stata Listserver


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

st: RE: Accessing the path and filename of currently open logfile.


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Accessing the path and filename of currently open logfile.
Date   Tue, 30 May 2006 13:58:34 +0100

A plain 

. log 

returns the information you need as r-class stuff. 
This is documented at [R] log. 

With commands of the kind you indicated, 
I have done what you outline, split with 
-gettoken- and then use -syntax-. It is 
worth knowing that -syntax- looks at the 
contents of local 0. Thus you need to 
assign that before each call to -syntax-. 
Note also that each -syntax- call will
zap (overwrite, possibly with empty strings)
the contents of local macros like varlist, 
if, in, etc. Hence you may need to save 
these before any second -syntax- call. 

Nick 
n.j.cox@durham.ac.uk 

David Elliott
 
> I'd like to test to see if (1) a  logfile is open and (2) 
> capture its name.
> The logfile name does not seem to be part of the creturn c() system
> values although the currently used file name -c(filename) - and pwd
> -c(pwd) are available.
> 
> Is there an equivalent to mata's pathsplit(path,path1,path2) command
> which would be very useful for filename handling?  I have found the
> undocumented _getfilename which is useful for popping the filename off
> the end of a path/filename string and one can then do a bit of
> manipulation to get the path, filename and extension for further
> manipulation.
> 
> Currently I have the following which will do the job:
> 
>   // Get the filename, path and extension for the log file.
> quietly log
> local log = r(filename)
> if "`log'" != "." {
>     _getfilename "`log'"
>     local logfile =  r(filename)
>     local logpath = subinstr(substr("`log'",1,
> length("`log'")-length("`logfile'")),"\","/",.)
>     gettoken nameonly extonly: logfile, parse(".")
>     local logstem "`logpath'""`nameonly'"
>     local extonly = substr(`"`extonly'"',2,.)
>     di in gr "`logpath'" in ye "`nameonly'" in gr "." in 
> white "`extonly'"
> }
> else {
> 	di in red "No logfile open"
> }
> // end excerpt
> 
> The other question I have is whether there is a way for -syntax- to
> handle command lines in the form: -cmd1, options: cmd2, options- or is
> it always necessary to nibble the command line apart with gettoken, or
> at least to get the left and right halves into a form for syntax to
> handle.  If not obvious already, I am trying to create a "wrapper" for
> another command(s).  If one didn't want the wrapper command to have
> options, one could simply use -cmd1 cmd2,options- that could be parsed
> by syntax.  It is the need to have the ",options" and the ":"
> separator following cmd1 that causes the difficulties.
> 
> This is my first foray into writing this kind of ado and I'd
> appreciate any insights or cautions from the pros.  Thanks.

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