Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Getting number of files via -fs-


From   Partho Sarkar <[email protected]>
To   [email protected]
Subject   Re: st: Getting number of files via -fs-
Date   Wed, 7 Mar 2012 14:21:35 +0530

Great- thanks Nick.  That *was* quick!  And really appreciate your
lucid explication of the quotes- will try to internalise it.

Partho

On Wed, Mar 7, 2012 at 2:15 PM, Nick Cox <[email protected]> wrote:
> -fs- is from SSC. (You are asked to explain _where_ user-written files
> come from.)
>
> . di `: word count `r(files)''
>
> works for me. I never insert spaces in filenames on purpose, but I
> tried out one such example, and it didn't throw -fs-.
>
> What are you doing wrong?
>
> " " are string delimiters; so you told -display- that its argument was
> a string, so your punishment is that you are obeyed.
>
> `"  "' bind a string into one "word", sensu Stata, and the count is 1
> as a result.
>
> If it's any comfort, experienced users can often get bitten by these
> small points too; experience just means that you get faster at
> correcting mistakes, not that you don't make them.
>
> Nick
>
> On Wed, Mar 7, 2012 at 8:16 AM, Partho Sarkar <[email protected]> wrote:
>> I am using Nick Cox's -fs- utility to automate a recurrent append
>> files operation (that part works like a charm!)  As a part of this, I
>> now need to keep track of of the number of  files  processed.  For
>> some reason, I simply cannot get this part right.  Here is what I
>> tried (there are 7 (seven)  files in the directory):
>>
>> ----------------------------CODE
>> BEGIN-----------------------------------------------------
>> // First attempt
>> fs *.dta
>> // displays ab_c.dta c_def.dta ... (7 files)
>> local numfiles: list sizeof `"`r(files)'"'
>> // With nested double quotes (tried with single quotes too-doesn't
>> seem to make any difference)!
>> // Error message: _""ab_c.dta" "c_def.dta"  invalid name
>>
>> // Second attempt
>> fs *.dta
>> local numfiles : word count "`r(files)'"
>> di "`numfiles'"
>> // Error: shows "9" (no quotes) !
>>
>> // Last attempt -with nested double quotes again
>> fs *.dta
>> local numfiles : word count `"`r(files)'"'
>> // Shows 1 (the number one)!
>>
>> -------------------------------CODE
>> ENDS--------------------------------------------------------
>>
>> What am I doing wrong? :-)  Or should i be using some other means
>> altogether?  (Sorry if this is too trivial !)
>>
>
> *
> *   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/

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index