Você pode usar um FOR / F e fazer referência ao caminho completo da lista de arquivos, como mostrado abaixo.
Isso essencialmente lerá cada linha da lista de arquivos para a qual você aponta, linha por linha, e iterará o valor retornado (conteúdo de cada linha) para o XCOPY comando para processar em conformidade.
Sintaxe da linha de comando
FOR /F "USEBACKQ TOKENS=*" %F IN ("C:\Folder\FileList.txt") DO XCOPY /F /Y "C:\SourceFolder\%~F" "C:\DestinationFolder\"
Sintaxe de script em lote
@ECHO ON
SET FileList=C:\Folder\FileList.txt
SET Source=C:\SourceFolder
SET Destination=C:\DestinationFolder
FOR /F "USEBACKQ TOKENS=*" %%F IN ("%FileList%") DO XCOPY /F /Y "%Source%\%%~F" "%Destination%\"
GOTO :EOF
Script Logic Notes
The
USEBACKQ
option used in the FOR loop will ensure the file list can still be read if the file list name or it's path has any spaces in it and you need to double quote the file list path
- E.g.
SET FileList=C:\Folder Name\File List.txt
- Without the
USEBACKQ
the FOR loop would error out in a case like thisThe
TOKENS=*
option used in the FOR loop will ensure the the entire value is returned as it's read from the file list even if that value has a space in it
E.g. File list has a value of
File 00 11.jpg
so the value has a space on a line
- Without the
TOKENS=*
the FOR loop would only return the value portion of that line before the first space and not the value as expected (i.e.File
)Using these options even when not needed does not seem to cause any harm and should you ever introduce such a value or variable into the mix of the script, it'd already be able to handle such cases accordingly.