I have a number of files that follow a pattern like this:
<BaseName> . <Version> [ - <Tag> - <#> ] . <Extension>
For example:
basename.1.0.0.ext
basename.1.0.0-aaa-1.ext
basename.1.0.0-aaa-2.ext
basename.1.0.0-aaa-3.ext
basename.1.0.0-bbb-1.ext
basename.1.0.0-bbb-2.ext
basename.1.0.0-bbb-3.ext
Now I need to write a strict that will copy just file with a certain 'tag' part (or no 'tag') an target folder. For example:
xcopy *-aaa-*.ext \\server\path /f /y
Will copy only files with the 'aaa' tag. So far so good.
The problem is that the script also needs to work for files with no 'tag', basically I need everything that matches *.ext
except what matches *-*.ext
.
Unfortunately, I have a number of restrictions here:
- I am not able to change the name pattern or location of these files.
- The 'version' part is not known, so
*.1.0.0.ext
will not work. - The 'version' is not a fixed length, so
*.?.?.?.ext
will not work. xcopy
's exclude parameter doesn't accept a pattern, only a list of files, so this won't work.- I am stuck using batch scripting for this. Invoking PowerShell is not entirely out of the question, but it would require a fair amount of overhead to get it working, so I'd like to avoid this if possible.
The actual script will have to look like this:
xcopy "%SOURCE%" "%DEST%" /f /y
And the variables used by this script will be saved in an external configuration file.
How can I write this script so that it works with any set of files, both a specific 'tag' and without any 'tag'?