Statalist


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

st: Re: too many files for dirlist


From   n j cox <[email protected]>
To   [email protected]
Subject   st: Re: too many files for dirlist
Date   Tue, 18 Sep 2007 17:40:30 +0100

-dirlist- isn't that old -- it was published by Morten Andersen on SSC in 2005. However, Michael is right: its basic approach -- for file names -- of calling up OS commands is unnecessary given the Stata hook he
outlines. But -dirlist- does more than that.

Nevertheless, as a convenience, an alternative command (even older,
as it dates from 2004) based on the syntax Michael recommends is -fs-,
also from SSC. (The name -fs- was meant to evoke memories of -ds-,
currently undocumented by StataCorp, but still in official Stata and still loved by its putative author.)

That all leaves the original question unanswered. I haven't used
-dirlist- previously, given -fs- as an alternative, but my experiments
lead me to suppose that Carlos' problem will be solved if he types

di "`r(fnames)'"

not

di r(fnames)

Hitherto, I have been cavalier about the difference, but for this problem it appears important. In other words, the problem is not
in -dirlist- but in what you do afterwards.

Nick
[email protected]

Michael Blasnik

-dirlist- is an older user-written ado file. But you don't need it to get a list of file names. See -help extended_fcn- and look at the dir function. Here's an example for retrieving a list of all Stata dta files in the current directory:

local fnames: dir . files "*.dta"

Carlos Eduardo Hernandez Castillo

> I have been using dirlist but it seems it has a maximum number of characters
> to retrieve in the return macros. For example, in a directory that contains
> the following files:
>
> 13areas.dta 7areas.dta Barranquilla.dta Bogota.dta Bucaramanga.dta Cali.dta
> Cartagena.dta Cucuta.dta Ibague.dta Manizales.dta Medellin.dta Monteria.dta
> NalECH.dta NalENH.dta OcupadosNacional.dta Pasto.dta Pereira.dta
> Proporciones.dta TotalesNacional.dta
>
> "display r(fnames)" would retrieve:
>
> 13areas.dta 7areas.dta Barranquilla.dta Bogota.dta Bucaramanga.dta Cali.dta
> Cartagena.dta Cucuta.dta Ibague.dta Manizales.dta Medellin.dta Monteria.dta
> NalECH.dta NalENH.dta OcupadosNacional.dta Pasto.dta Pereira.dta
> Proporciones.dta TotalesNacional
>
> I have been looking for an alternative to get the names of all the files but I
> have not been able to do so, do you have any idea? I am using Stata 9.2.

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