views:

1169

answers:

5

I'd like to copy several known files to another directory as a part of a post-build event, but don't want to have lines and lines of "copy [file] [destination] [switches]" in my build event. If possible, I'd like to list out the files I'd like to copy using a similar format: "copy [file 1] [file 2] [file 3] [etc...] [destination] [switches]". However, Windows doesn't seem to like this type of format. Any ideas? Thanks!

+1  A: 

Use the <Copy> MSBuild task.

David Schmitt
A: 

Use ant, or install cygwin and use cp

Jherico
A: 

you need to put a + between each source file

edit:

C:\>copy /?
Copies one or more files to another location.

COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/A | /B ] source [/A | /B]
     [+ source [/A | /B] [+ ...]] [destination [/A | /B]]

I guess you guys are correct, I read the online help and it looks like you can specify multiple source files, but it actually concatenates the files together.

Well, to save some face, you may be able to get xcopy to work by specifying a directory (or wildcard) as the source and using the /exclude parameter if that would take too many files. You can also check out the /U option (Copies only files that already exist in the destination) or /D (copy by date)

Dolphin
**Nice***Joke**
Anton Tykhyy
-1 because this was something I had never seen this before, so I tried it (Win XP command prompt). It didn't work.
PTBNL
This command will glue all the source files together, PTBNL — see copy /?
Anton Tykhyy
@Anton, Yeah that's what I saw, but that's not what the poster wanted!
PTBNL
+6  A: 

You can use 'for' either in a batch file or directly from the command prompt:

for %I in (file1.txt file2.txt file3.txt) do copy %I c:\somedir\

Wildcards are supported in the filelist as well:

for %I in (*.txt *.doc *.html) do copy %I c:\somedir\

For more info, just type for /? from a command prompt, or for a much easier to read help use Start->Help and Support and search for "For". On my XP Pro box, it was item 15 in the full text search results.

Ken White
Works like a charm! The only thing is that I have to double up my percent signs when used in a build event (i.e. for %%I in...). Thanks!!
Pwninstein
+2  A: 

XP and Vista replaced xcopy with robocopy, and it will do exactly what you want. The syntax for what you want feels backwards at first, but it does the job:

robocopy source\folder a\dest\folder file1.exe file2.bat file3.dll file4.txt
Iceman
Dolphin
@Dolphin: good catch; I had it on my XP machines and didn't remember installing it myself, but you're right.
Iceman
Neither XP nor Vista "replaced" xcopy. It's still there.
Timwi
@Timwi, poorly phrased on my part. What I meant is that it was replaced as the preferred way to copy multiple files.
Iceman