Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: getting list of open files


From   Eric Booth <[email protected]>
To   [email protected]
Subject   Re: st: getting list of open files
Date   Tue, 5 Jan 2010 23:27:52 -0600

<>

You can store the handle names in a global macro each time you create a new handle (and -macro drop- the handle when you close it) & then get them into a single list in a global macro using the extended_function   all {globals} ["pattern"] .  You can manipulate them from there.   For example:

*********
clear all
cap file close _all
cap macro drop _all
local sf "`pwd'"
	
**for each handle you create, make a global macro**
forv n= 1/10 {
tempfile testm`n'
	file open handle`n' using "`sf'/testm`n'", write replace
	global handle`n'  "handle`n'"     //<-- create the global
file write handle`n' "test" _n	
}

//If you close a handle, you'll need to drop the macro
file close handle5
macro drop handle5   //<-- remove the global


*----------------------------------examine open handles
//store all open handles in a single macro//
global overview: all globals "handle*" 
macro li overview

//use the list of open handles//
foreach m of global overview {
	di "`m'"
	file write `m'   _page(2)  " the end " 
	/* something else */
	}

*~*
file close _all
*****************
This would be less messy if the -file query- command could return the open handles along with the number of open files r(N).

~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754


On Jan 5, 2010, at 1:28 PM, Jeph Herrin wrote:

> 
> I have been using -file- and it's subcommands to
> do a lot of report writing; thus, I have written a
> number of subroutines that use file handles to output
> formatted text.
> 
> These would be easier to code if I could get a list of
> open file handles. -file query- (which seems to have
> no documentation other than that it exists) will output
> the list of file handles, their type, and status, but
> only returns -r(N)-, the number of open files.
> 
> Is there another way to get the list of open file handles
> in a macro where I can manipulate them? Barring something
> simpler, I can write a script to open a log file, call
> -file query-, close the log file, then parse the log file
> into a table, but that's messy for something I would want
> to call in all of my subroutines.
> 
> Any other ideas?
> 
> thanks,
> Jeph
> 
> *



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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