

Highlight each file which you want to rename.Copy all the files which you want to rename, in a single folder.
Batch file rename dos install#
You can simply use Windows Explorer to rename files If you don’t have a fancy renaming task at hand, or don’t want to install anything.

To check other commands Liu Wei has written, go to Liu Wei at IDEAS.Bulk File Rename on Windows Use Windows Explorer to rename filesīefore we move to the commands ant batch, let’s see how we can rename multiple files at once in bulk using file explore. Its syntax is straight forward:įren file_extension, from( str1) įor example, to get rid of the prefix "mus" from the names of do-files and datasets in the folder, I first installed the program and changed the directory:Īnd, all those "mus" were gone.

fren- (Liu Wei, 2010) renames file names (with specific file extensions) in the current directory. Renaming the files one by one seems crude (something that a muggle would do in Harry Potter's world) somebody must have written a Stata program for this! So I googled using the keywords "stata rename filenames", and there it was: "FREN: Stata module to batch rename files (Windows only)". When I unzipped the file, I found that all the file names in the folder have the prefix "mus". Today I downloaded resources (do-files and datasets) used in the the book Microeconometrics Using Stata, Revised Edition (Cameron and Trivedi, 2009). Now, all my MUS file names are as they were. To bring back the prefix "mus" to my files:įpref dta, prefix( mus) /* adds the prefix "mus" to all *.dta files in the current directory */įpref do, prefix( mus) /* adds the prefix "mus" to all *.do files in the current directory */ I can now type " help fpref", which will open the -help- window with the following information: -help fpref. I have saved my fpref.ado (and its corresponding help file fpref.sthlp) and changed my directory.

Finally, a Stata program always ends with an "end". The second part of the body concatenates prefix to the old file names, which we have listed in a local macro. In this program, the first part of the body, with the while loops, returns an error if the operating system used is not Windows or the prefix is missing or separated by blank spaces. The body of the program follows the syntax. By typing "version 10" in the third line, the command that was named -fpref- is compatible with Stata 10 or newer versions of Stata. In the next line "prog define fpref", the command is named as -fpref. If it does not exist, Stata will not return an error and will continue to read the next line because of the command -capture- (this line can be deleted in the final version of the ado file). The first line "capture prog drop fpref" drops the program called -fpref-, if it exists. So, here is the little program -fpref- that I wrote (my first ado-file) to add a prefix to file names by batch: fpref.ado Now, I want them back! -fren- is not helpful. Yesterday, I used -fren- to delete the prefix "mus" in the file names of all data and do-files used in the book "Microeconometrics Using Stata" (MUS).
