Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Eric Booth <ebooth@ppri.tamu.edu> |

To |
"<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: calculate the length of all do-files in a folder, including subfolders |

Date |
Tue, 21 Jun 2011 19:56:48 +0000 |

<> Also, you mentioned looping over sub-directories in your question...see this thread for some suggestions on how to modify my previous example to loop over sub-folders: http://www.stata.com/statalist/archive/2010-11/msg00113.html - Eric __ Eric A. Booth Public Policy Research Institute Texas A&M University ebooth@ppri.tamu.edu Office: +979.845.6754 On Jun 21, 2011, at 2:50 PM, Eric Booth wrote: > <> > > You could use `r(lnum)' stored by -hexdump- to get the number of lines. > Here's a way to loop over all .do files in a directory and count up the # of lines: > ((be sure to replace <yourfolderhere> with your folder path (e.g. "C:\myfolder" or "/users/me/documents//")) > > ***********! > global files: dir "<yourfolderhere>" files "*.do", nofail respectcase > di `"$files"' > loc tot = 0 > foreach f in $files { > qui hexdump "<yourfolderhere>`f'", results > di in r "`f': `r(lnum)'" > loc tot = `tot' + `r(lnum)' > } > > di "`tot'" //this contains the overall total > ***********! > > - Eric > > __ > Eric A. Booth > Public Policy Research Institute > Texas A&M University > ebooth@ppri.tamu.edu > > > On Jun 21, 2011, at 1:42 PM, Dimitriy V. Masterov wrote: > >> I need to calculate how many lines of code were written for a >> particular project. The do-files are in various nested subdirectories >> of a single folder on a Windows 7 machine. Is there a way to avoid the >> tedium of doing this by hand? >> >> DVM >> * >> * 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/ * * 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/

**References**:**st: calculate the length of all do-files in a folder, including subfolders***From:*"Dimitriy V. Masterov" <dvmaster@gmail.com>

**Re: st: calculate the length of all do-files in a folder, including subfolders***From:*Eric Booth <ebooth@ppri.tamu.edu>

- Prev by Date:
**Re: st: calculate the length of all do-files in a folder, including subfolders** - Next by Date:
**Re: st: First stage F stats - xtivreg** - Previous by thread:
**Re: st: calculate the length of all do-files in a folder, including subfolders** - Index(es):