*! version 1.0 2011-12-22
help rmfiles (vs1.0: 2011-12-22)

Title

rmfiles -- Removing matched files and possibly, if applicable, corresponding empty directories.

Syntax

rmfiles [, folder(string) match(string) subs(string) rmdirs oldstx]

Description

rmfiles
is a program that helps to remove files in a quite generally applicable fashion -
through matched filenames in a stated directory, and also - if selected -
in all matched subdirectories. If selected, and applicable, any empty matched
directories will also be removed. The simplest syntax is purely based on defaults.
All options are optional.

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.)

rmdirs An indicator for whether, or not, any matched empty directories (i.e. folder or corresponding subdirectories by match)
should be removed as well.

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 all files in current working directory.

. rmfiles

2. Remove all files with prefix name located in cwd-subdirectory data.

. rmfiles , folder(".\data") match("name*")

3. Same as Example 2, but in this case the corresponding folder - if empty - is also deleted

. rmfiles , folder(".\data") match("name*") rmdirs

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

. rmfiles , folder(".\data") match("name*") subs("2011*") rmdirs

5. Same as Example 4, but in this case using the old syntax, leading to case-insensitive matching.
For example, all files starting with strings NAME or Name will also be matched in this case.
Use lower case, see note above.

. rmfiles , folder(".\data") match("name*") subs("2011*") rmdirs 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

renfiles - renaming 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, erase, rmdir.