Statalist The Stata Listserver


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

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


From   "David Elliott" <[email protected]>
To   [email protected]
Subject   st: Accessing the path and filename of currently open logfile.
Date   Tue, 30 May 2006 09:49:53 -0300

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.

DCE
--
David Elliott
*
*   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