Copy Files From Multiple Folders Using Robocopy and a Text File List

server room

At work today, I had to copy hundreds of files from two different network folders to my local computer (Windows PC). The manual way would have taken all day and been painfully boring…so I scripted it! Here’s how you can copy files from multiple folders using ROBOCOPY and a text file list.

The Setup

Remote

I have a list of files on a remote server directory that I want to copy locally, but I don’t want to copy all the files in that directory. There may be 10,000 files in there, but I only need the 1,000 files I have listed in “filelist.txt”.

Local

The directory I’m copying to locally is C:\Copied. I want to maintain the same folder structure as the remote server, so I’ll use C:\Copied%src% as the destination, which comes out to be C:\Copied\Folder1\Documents.

The Script

@echo off

set directory=\\remoteserver\stuff\documents
set src=\Folder1\Documents
set dest=C:\Copied%src%

for /f "delims=" %%i in (filelist.txt) do robocopy %directory%%src% %dest% "%%i"
echo.
echo Press any key to end...
pause> nul

I tested my script first with just a few files listed in filelist.txt, just in case something went terribly wrong. Once you verify that it works for a few files (you can see the ROBOCOPY output before you close the command line window on your test run), just add the rest of the file names to the filelist.txt and fire it up!

3 Quick Notes

First, when you’re working with remote server shares, you must take file permissions into account, so make sure your account has access to the files you’re copying.

Second, if your directories have spaces in their names, you’ll need to use quotation marks (” “) as needed:

"%directory%%src%" "%dest%"

Lastly, make sure you pay attention to your own directory structure. All of the above is just a generic example meant to help you see how it’s done.

Did This Work For You?

Leave a comment below to let me know if this helped you or not. Feel free to ask a question or post any problems you are having with your script. I’ll do my best to respond and help out.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.