Search code examples
batch-filexcopy

xcopy from same location but different computers


How do I do this? After copying the files, I need them to be renamed to their origin's computer name.

I got

for %%a in (computerlist.txt) do xcopy %%a\C$\file.txt D:\ /C

Will this work? I'm lost in the renaming part though.

It seems like %%a in \%%a\C$\file.txt is not accepted. When I run it, it becomes \computerlist.txt\C$\file.txt. Same with the destination path. I even tried to put the full path of computerlist.txt inside the parenthesis but still did not work.


Solution

  • Off the top of my head, this should get you started:

    for /f %%a in (computerlist.txt) do xcopy \\%%a\C$\file.txt D:\%%a.txt /C
    

    If computerlist.txt has the leading \\ in the computer name, remove them from the xcopy \\%%a portion of the line.