*! version 2.1 2011-12-22
help renfiles (vs2.0: 2011-07-19) (vs2.1: 2011-12-22)

Title

renfiles -- Renaming matched files by replacing specified sign/substring with another sign/substring.

Syntax

renfiles [, folder(string) match(string) subs(string) insign(string) outsign(string) erase oldstx]

Description

renfiles
is a program that helps to rename files in a quite generally applicable fashion -
changes applied to all matched filenames in a stated directory, and also - if selected -
in all matched subdirectories. The simplest syntax is purely based on defaults. All options are optional.

If the sign
to-be-replaced is a dot, the last dot is not changed (keeping file-suffix).

Options

folder(string) Defines the directory from within where to look for files.
The default directory is the current working directory (cwd; '.').

match(string) Defines the matching criterion used in order to select files
from the selected directory folder, and - if selected - matched (by subs) subdirectories.
The default is all files in the directory/directories ('*').

subs(string) Defines whether, or not, matched files (by match) in corresponding matched
subdirectories (recursively; based on here defined matching criterion) also should be affected.
(Matching must be present at all levels.)

insign(string) The sign to be replaced when applying the used criterion match
with respect to the files in the directory folder, and - if selected - matched (by subs) subdirectories.
Is case-sensitive if option oldstx is not selected. The default is the dot sign ('.').

outsign(string) The sign to be replacing (the to-be-replaced sign insign) when
applying the used criterion match with respect to the files in the directory folder,
and - if selected - matched (by subs) subdirectories. To remove the sign insign,
i.e. replacing it with an empty space, use string null. The default is the underscore sign ('_').

erase An indicator for whether, or not, the original matched (but unchanged) files should be removed from
the directory.

oldstx An indicator for whether, or not, Stata 9 syntax (as compared to Stata 11 syntax) should be assumed
with respect to extended macro functions. If stated, matching will not be case-sensitive and hence all matching
strings string should be entered in lower case.

Examples

1. Remove dots from all files in current working directory and replace them with underscores.

. renfiles

2. Remove dots from all files with prefix name located in cwd-subdirectory data and replace them with dashes.

. renfiles , folder(".\data") match("name*") outsign("-")

3. Same as Example 2, but in this case all matched, original, files are also to be erased.

. renfiles , folder(".\data") match("name*") outsign("-") erase

4. Remove all occurrences of file and replace them with abbreviation f in all files with filenames including string-part proj3 located in cwd-subdirectory results.

. renfiles , folder(".\results") match("*proj3*") insign("file") outsign("f")

5. Same as Example 4, but in this case all Denmark-specific letters ('å', 'æ' and 'ø') are removed (replaced with anglofied counterparts) in a sequential manner; original/temporary files are erased.

. renfiles , folder(".\results") match("*proj3*") insign("å") outsign("aa") erase

. renfiles , folder(".\results") match("*proj3*") insign("æ") outsign("ae") erase

. renfiles , folder(".\results") match("*proj3*") insign("ø") outsign("oe") erase

6. Same as Example 4, but in this case all present empty spaces, within matched filenames, are removed (replaced with null space; see note above).

. renfiles , folder(".\results") match("*proj3*") insign(" ") outsign("null")

7. Same as Example 4, but in this case corresponding actions are also performed with respect to all subdirectories
(recursively, see note above) with names starting with string 2011.

. renfiles , folder(".\results") match("*proj3*") subs("2011*") insign("file") outsign("f")

8. Same as Example 7, but in this case using the old syntax, leading to case-insensitive matching.
For example, all files including strings PROJ3 or Proj3 will also be matched in this case. Use lower case, see note above.

. renfiles , folder(".\results") match("*proj3*") subs("2011*") insign("file") outsign("f") oldstx

Requires

Stata 9; newer versions needed when option oldstx is not used.

Author

Lars Ängquist

Lars.Henrik.Angquist@regionh.dk

lars@angquist.se

Acknowledgements

Testing assistance by Birgit Marie Nielsen (Thanks Birgit! / LÄ)

Related commands (downloadable on SSC)

mvfiles - moving set of matched files

rmfiles - removing set of matched files

use10save9 - save Stata 10/11 files as Stata 9 counterparts (also from within Stata 9)

excelsave - exporting set of matched files to Excel (.xls or .xlsx)

Also see

Help: [help pages on] extended_fcn, dir, copy, erase.