Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

Can I copy multiple named files on the Windows command line using a single "copy" command?

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!

question from:https://stackoverflow.com/questions/922607/can-i-copy-multiple-named-files-on-the-windows-command-line-using-a-single-copy

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...