Search code examples
windowsxcopy

Xcopy certain file names only


I've never used the Xcopy feature before and I was wondering if it would be possible to use xcopy to copy only certain files within a directory tree.

For example, suppose I have the following documents: \servername\generateddocuments\2014\20141231\GUID1.doc \servername\generateddocuments\2014\20141231\GUID2.doc \servername\generateddocuments\2015\20150101\GUID3.doc \servername\generateddocuments\2015\20150101\GUID4.doc

Now, suppose I have a spreadsheet that tells me which .doc files I need to copy: GUID1.doc GUID3.doc

Is there a way to base the xcopy on the spreadsheet(or txt document) so I don't copy the files I don't need?


Solution

  • I don't think xcopy can read files to include from a file. But you can create a batch file that does this:

    for /F "tokens=*" %%A in (documents.txt) do (
       copy %%A x:\targetfolder\
    )