*! version 1.0 2012-01-04
help mvfiles (vs1.0: 2012-01-04)

Title

mvfiles -- Moving matched files into defined directory.

Syntax

mvfiles [, infolder(string) outfolder(string) match(string) subs(string) makedirs erase oldstx]

Description

mvfiles
is a program that helps to move, or copy, (sets of) files in a quite generally applicable fashion -
through matched filenames from a stated in-directory - and also, if selected, from all matched subdirectories -
into a defined out-directory. If selected, any non-existing out-directory will automatically be created before move.
If selected, corresponding files will be removed from old location. The simplest syntax is purely based on defaults.
All options are optional.

Options

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

outfolder(string) Defines the directory where to move matched files.
The default directory is the current working directory (cwd; '.'), but if
infolder=outfolder then the files will be put into the common - created if needed -
subdirectiry mvfiles. If option makedirs is selected, the outfolder-directory
will generally be created if not already existing.

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

makedirs An indicator for whether, or not, outfolder should be created if not already existing.

erase An indicator for whether, or not, any original matched files should be removed as well
(conditioned on successful move, i.e. that outfolder existed or was created).

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. Copy all files in current working directory to subdirectory mvfiles (which is created if nonexisting).

. mvfiles

2. Move all files with prefix name located in cwd-subdirectory data to subdirectory mvdirs
(which is created if nonexisting), original files are erased.

. mvfiles , infolder(".\data") outfolder(".\data") match("name*") erase

3. Copy all files with prefix name located in cwd-subdirectory data to user-defined subdirectory
yes (which is created if nonexisting).

. mvfiles , infolder(".\data") outfolder(".\data\yes") match("name*") makedirs

4. Move all files located in cwd-subdirectory data - and in subdirectories with prefix 2011 - to
user-defined subdirectory yes (if existing).

. mvfiles , infolder(".\data") outfolder(".\data\yes") match("*") subs("2011*") erase

5. Same as Example 4, but with matching based on prefix name, and in this case also 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.

. mvfiles , infolder(".\data") outfolder(".\data\yes") match("name*") subs("2011*") erase oldstx

Requires

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

Author

Lars Ängquist

Lars.Henrik.Angquist@regionh.dk

lars@angquist.se

Related commands (downloadable on SSC)

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