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

Re: st: RE: combining many data files

From   "Michael S. Hanson" <>
Subject   Re: st: RE: combining many data files
Date   Sat, 22 Nov 2008 12:26:16 -0500

On Nov 19, 2008, at 10:16 PM, Mingfeng Lin wrote:

For renaming files (as Kyle mentioned), I just remembered a trick to
rename a large number of files simultaneously on Windows (at least on
XP): select all files you want to rename, then, with cursor pointed at
the first file (all other files still selected), right click and
choose "rename".  Then type in something like
and you'll see all other files renamed into file(2).dta, file(3).dta
etc. But it only works on Windows - for Mac users the extended
function could be the only way out.

Macintosh users have numerous ways to accomplish the objective of batch renaming files, such as in the above example:

1. Use an Automator action. It is quite easy to link a few Finder actions and save as a contextual menu plug-in for the Finder that you can use to rename files in all sorts of ways, including sequential numbering. Just control-click or right-click on the selected files and select your saved plug-in. Alternatively, you can download a pre- made action from, say, < rename/>.

2. Use a Unix script. Indeed, one could write a script, save it as an executable file, and run it from within Stata with the -shell- command. There are an extremely large number of ways to write such a script; here is a quick one that works from the bash command line (i.e., within, similar to the example above:

i=1; for x in *.dta; do cp -p $x file$i.dta; i=$(($i+1)); done

Notice here I have actually copied the files instead of simply renaming them, so the originals are preserved. To just rename, replace "cp -p" with "mv".

3. Use a freeware/shareware utility. There are at least a dozen; here are a few:

The first two require Mac OS X 10.5; the last will run on version 10.3 and up.

Hope this helps,
*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index