Statalist


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

RE: st: How do I write a directory listing to a file under Windows


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: How do I write a directory listing to a file under Windows
Date   Thu, 14 May 2009 14:09:17 +0100

<>
Pathological tinkerers will note that this can be shortened slightly.
(Untested code, however.) 

prog define click
*! Clickable stuff
	version 8 
	args suffix
	local name: dir `"`c(pwd)'"' files "*.`suffix'"
	foreach n of local name { 
		noi di as txt `"{browse `"`n'"'}"'
	}
end

Nick 
[email protected] 

Roy Wada

Look at -cdout-, available from SSC, which will produce a clickable for
the cd folder.
 
Also at -capfile-, which will do it for .txt or .smcl log files.
 
Directly opening .do or .dta will trigger a new session of Stata, which
was
not useful to me.

You might extract file names directly from macro. This is
platform-independent.

prog define click
*! Clickable stuff
args suffix
local name: dir `"`c(pwd)'"' files "*.`suffix'"
tokenize `"`name'"'
local num 1
while `"``num''"'~="" {
   local var `"``num''"'
   local cl_text `"{browse `"``num''"'}"'
   noi di as txt `"`cl_text'"'
   local num=`num'+1
}
end
 
click txt
click do

Ulrich Kohler 
 
> I drafted two little programs -ldta- and -ldo- that provide a
clickable
> list of .dta files or .do files in the working directory.
> Unfortunatelly, as they stand, the programs only work for Unix/Linux,
as
> I do not know how I can write a text-file with filenames into a file
> under Windows (see program code below). I thought of
> 
> . log using x
> . quietly dir *.dta
> . log close
> 
> but obviously this doesn't help. I also thought of 
> 
> sh dir *.dta> 11
> 
> but I cannot test it as I don't have access do Windows-machine with
> Stata right now.
> 
> Any hints most appreciated.
> 
> Uli
> 
> ---------------------------------------------------ldo.ado
> *! version 0.1 Mai 14, 2009 @ 11:05:32 UK
> *! Clickable list of .do files
> program ldo
> version 10.0
> 
> 
> // Create file with File-list
> tempname dolog
> sh ls *.do> `dolog'
> tempname dolist 
> 
> // Open with file
> file open `dolist' using `dolog', read text
> local linenum = 0
> file read `dolist' line
> 
> // Display filenames with clickable items
> while r(eof)==0 {
> local linenum = `linenum' + 1
> display as text %5.0f `linenum' ///
> as result `"{col 6} `macval(line)' "' ///
> `"{right:[{stata `"view "`macval(line)'""':view}]{space 5}[{stata
> `"doedit "`macval(line)'""':edit}]{space 5}[{stata `"do
> "`macval(line)'""':do}]{space 5}[{stata `"erase
> "`macval(line)'""':{err}erase}]}"' 
> file read `dolist' line
> }
> file close `dolist'
> 
> end
> exit

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