2009-05-22

Copying all the files that match a certain pattern in a directory structure over to a single directory

For a long time I have wanted to collect all the files matching a certain pattern (Inv*.pdf) from a directory structure and copy them all to a single directory.

A Windows utility, xxcopy, has a command line switch to do exactly this.

I also found a forum discussion on how to do it in both Windows and *nix. And another one just about Windows.

With xxcopy the command line syntax to do what I wanted is:

xxcopy d:\contract\inv*.pdf d:\procurement\invoices\ /SG /BI

The /SG switch tells it to recursively (i.e. including from subdirectories) copy all of the files matching the wildcard pattern to the single target directory (i.e. without recreating the subdirectories under the target).

The /BI switch only copies files that either do not exist in the target directory or are newer versions of existing files.




No comments: