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
613 views
in Technique[技术] by (71.8m points)

msbuild - Using xcopy to copy files from several directories to one directory

Is it possible to use xcopy to copy files from several directories into one directory using only one xcopy command?

Assuming that I have the directory tree

rootSourceSub1Sub2

I want to copy all .xml files from the directory rootSource including sub folder to rootDestination. I don't want to copy the folder structure, just the files.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

As DandDI said, you don't need xcopy. for statement helps much. However, you don't need to state process outcome of dir command as well, this command helps better

for /R c:source %f in (*.xml) do copy "%f" x:destination

By the way, when you use it from a batch file, you need to add spare % in front of variable %f hence your command line should be;

for /R c:source %%f in (*.xml) do copy %%f x:destination

when you use it within a batch

  • Should surround %f with double quotes otherwise it will fail copying file names with spaces

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

...