Get RoboCopy to read list of files to copy from a text fileIs it possible to get Robocopy to read a list of files that are to be copied from a text file or simillar?<br/><br/>Many Thanks© 2009 Microsoft Corporation. All rights reserved.Thu, 16 Jul 2009 19:16:45 Ze7ac9618-e9f4-49f8-878c-0c2f61ac8922http://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#e7ac9618-e9f4-49f8-878c-0c2f61ac8922http://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#e7ac9618-e9f4-49f8-878c-0c2f61ac8922Mike2010http://social.technet.microsoft.com/Profile/en-US/?user=Mike2010Get RoboCopy to read list of files to copy from a text fileIs it possible to get Robocopy to read a list of files that are to be copied from a text file or simillar?<br/><br/>Many ThanksThu, 02 Jul 2009 20:50:21 Z2009-07-02T20:50:21Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#e7c7c597-c970-4e92-844c-ed9d4d0155fehttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#e7c7c597-c970-4e92-844c-ed9d4d0155feAbqBillhttp://social.technet.microsoft.com/Profile/en-US/?user=AbqBillGet RoboCopy to read list of files to copy from a text fileHi,<br/> <br/> I just looked at robocopy's syntax, and it doesn't appear to support it directly, but it does look like you can specify multiple file specifications after naming the source and destination directories; e.g.<br/> <br/> robocopy c:\source d:\dest file1 file2 file3<br/> <br/> ..and so forth. If this list of file names gets very long, you may run up against command-line length limits. Alternatively, you can use a script to read a list of files and call robocopy multiple times. For example, in PowerShell, you could write:<br/> <br/> gc list.txt | % { robocopy c:\source d:\dest $_ }<br/> <br/> This code gets the content ('gc') of the file list.txt, and for each ('%') line, it executes the robocopy command ('$_' represents the current line).<br/> <br/> HTH,<br/> <br/> BillThu, 02 Jul 2009 22:33:26 Z2009-07-02T22:33:26Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#ab9b24d7-02eb-4db1-beaa-d0c8e2a424c9http://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#ab9b24d7-02eb-4db1-beaa-d0c8e2a424c9Brian Borghttp://social.technet.microsoft.com/Profile/en-US/?user=Brian%20BorgGet RoboCopy to read list of files to copy from a text fileC:\&gt; For /f %%f in (list.txt) do copy /y c:\source\%%f d:\destFri, 03 Jul 2009 01:11:28 Z2009-07-03T01:50:28Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#17b0fdac-2182-4111-90db-8a74b7d95761http://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#17b0fdac-2182-4111-90db-8a74b7d95761Salvador Manaois IIIhttp://social.technet.microsoft.com/Profile/en-US/?user=Salvador%20Manaois%20IIIGet RoboCopy to read list of files to copy from a text fileHere's a robocopy one-liner adapted from bnborg's answer above:<br/><br/>for /f %%f in (list.txt) do robocopy c:\source d:\dest %%f<br/><br/>Here's a VBS that copies files in a single robocopy call (provided the resulting strFiles does not fill up the CLI buffer):<br/><br/> <pre lang=x-vbnet>On Error Resume Next inputFile = &quot;.\list.txt&quot; Const conForReading = 1 Set objFSO = Wscript.CreateObject(&quot;Scripting.FileSystemObject&quot;)<br/>Set oShell=WScript.CreateObject(&quot;WScript.Shell&quot;) <br/><br/><br/>Set oInputFile = objFSO.OpenTextFile(inputFile, conForReading) Do Until oInputFile.AtEndOfStream arrstrFiles = oInputFile.ReadAll Loop arrFiles = Split(arrstrFiles, vbCrLf) strFiles = &quot;&quot; For i=0 to Ubound(arrFiles) strFiles = strFiles &amp; &quot; &quot; &amp; arrFiles(i) Next oshell.Run &quot;robocopy c:\source d:\dest&quot; &amp; strFiles</pre> Alternatively, you can do a robocopy call within the For-Next loop to copy each file listed in list.txt.<br/><br/>Regards,<br/><br/><strong>Salvador Manaois III<br/></strong>MCITP | <em>Enterprise &amp; Server Administrator<br/></em>MCSE MCSA MCTS(x5) CIWA C|EH <br/>My Blog: <a href="http://badzmanaois.blogspot.com/"><span style="color:#0033cc"><strong>Bytes and Badz</strong></span></a> <br/>My Shots: <a href="http://social.technet.microsoft.com/Forums/en-US/user/flickr.com/photos/badzmanaois"><span style="color:#0033cc"><strong>View My PhotoStream</strong></span></a>Fri, 03 Jul 2009 02:29:07 Z2009-07-03T02:29:07Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#a1024ae4-57ca-436c-845f-8c551c1511b2http://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#a1024ae4-57ca-436c-845f-8c551c1511b2AbqBillhttp://social.technet.microsoft.com/Profile/en-US/?user=AbqBillGet RoboCopy to read list of files to copy from a text fileFor completeness, here's a JScript version:<br/> <br/> <pre lang=x-js>var fso = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;); var wshShell = new ActiveXObject(&quot;WScript.Shell&quot;); var ts = fso.OpenTextFile(&quot;List.txt&quot;, 1); while (! ts.AtEndOfStream) { var file = ts.ReadLine(); if (file.length &gt; 0) wshShell.Run(&quot;robocopy c:\\source d:\\dest &quot; + file); } ts.Close();</pre> <br/> <br/> HTH,<br/> <br/> BillFri, 03 Jul 2009 19:48:39 Z2009-07-03T19:48:39Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#97b637c2-686f-46a2-89be-98b3adfb023ahttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#97b637c2-686f-46a2-89be-98b3adfb023aMike2010http://social.technet.microsoft.com/Profile/en-US/?user=Mike2010Get RoboCopy to read list of files to copy from a text fileHi,<br/><br/>I need it to copy specified folders as well, i tried modifying your code with the /R, but couldn't get it to work. <br/><br/>How would i add the ability to specify Folders as well?<br/><br/>Many ThanksMon, 06 Jul 2009 17:51:31 Z2009-07-06T17:51:31Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#0da458d3-5b34-4531-b84f-f733e765aa40http://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#0da458d3-5b34-4531-b84f-f733e765aa40AbqBillhttp://social.technet.microsoft.com/Profile/en-US/?user=AbqBillGet RoboCopy to read list of files to copy from a text fileHi,<br/> <br/> Can you be more specific about what exactly you want to accomplish?<br/> <br/> BillTue, 07 Jul 2009 16:13:17 Z2009-07-07T16:13:17Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#95ca1214-66fe-431c-9ce1-b6e5cb756deehttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#95ca1214-66fe-431c-9ce1-b6e5cb756deeMike2010http://social.technet.microsoft.com/Profile/en-US/?user=Mike2010Get RoboCopy to read list of files to copy from a text fileHi Bill,<br/><br/>The above code is only copying files, it doesn't seem to copy any folders across?<br/><br/>Thanks<br/><br/>MikeTue, 07 Jul 2009 17:15:04 Z2009-07-07T17:15:04Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#55329769-7431-45bf-82da-146a7423102dhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#55329769-7431-45bf-82da-146a7423102dAbqBillhttp://social.technet.microsoft.com/Profile/en-US/?user=AbqBillGet RoboCopy to read list of files to copy from a text fileHi Mike,<br/> <br/> Try adding the '/s' (copy subdirectories, but not empty ones) or the '/e' (copy subdirectories, including empty ones) parameter to robocopy's command line. (See 'robocopy /?' at a command prompt for more information.)<br/> <br/> HTH,<br/> <br/> BillTue, 07 Jul 2009 18:50:10 Z2009-07-07T18:50:10Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#f7059d49-db9b-4f3f-8c57-a6e40ee1086ahttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#f7059d49-db9b-4f3f-8c57-a6e40ee1086aMike2010http://social.technet.microsoft.com/Profile/en-US/?user=Mike2010Get RoboCopy to read list of files to copy from a text fileHi Bill,<br/><br/>I only want the folders that are named in the list.txt file to be copied across though. Adding a switch to the end copy's everything.<br/><br/>MikeTue, 07 Jul 2009 20:09:20 Z2009-07-07T20:09:20Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#454bd246-8551-4408-9994-15199bc9cd68http://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#454bd246-8551-4408-9994-15199bc9cd68perhofhttp://social.technet.microsoft.com/Profile/en-US/?user=perhofGet RoboCopy to read list of files to copy from a text fileIs there a particular reason you're totally into Robocopy on this one?<br/>Since it doesn't support file lists itself, maybe it's not the tool you should use?<br/>I doubt that calling Robocopy separately for every single file and folder on your list will be that efficient.Tue, 07 Jul 2009 20:16:49 Z2009-07-07T20:16:49Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#299e6ec4-97d2-432b-8cae-1edc93a08054http://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#299e6ec4-97d2-432b-8cae-1edc93a08054AbqBillhttp://social.technet.microsoft.com/Profile/en-US/?user=AbqBillGet RoboCopy to read list of files to copy from a text fileHi Mike,<br/> <br/> I'm afraid I don't understand what you want to do, then. Can you give us a specific example?<br/> <br/> BillTue, 07 Jul 2009 21:37:47 Z2009-07-07T21:37:47Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#9eb68909-076d-4fd0-97cd-505aa1bc5b29http://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#9eb68909-076d-4fd0-97cd-505aa1bc5b29Mike2010http://social.technet.microsoft.com/Profile/en-US/?user=Mike2010Get RoboCopy to read list of files to copy from a text fileWhat else is there?Wed, 08 Jul 2009 05:06:17 Z2009-07-08T05:06:17Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#d12827a0-723d-47c6-9808-0ca3732eaa17http://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#d12827a0-723d-47c6-9808-0ca3732eaa17perhofhttp://social.technet.microsoft.com/Profile/en-US/?user=perhofGet RoboCopy to read list of files to copy from a text fileRobocopy is great for replicating a whole structure from one place to another but if you want to call it a thousand times (one time for every file in a list) you should consider using something more lightweight like the regular copy command a built in fuction of the scripting language you're using.<br/><br/>Look at this thread for some examples:<br/><a href="http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/59eed295-a18f-4c78-9b87-cf211c2e58b2">http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/59eed295-a18f-4c78-9b87-cf211c2e58b2</a><br/><br/>You can modify the script to do objFSO.CopyFolder instead of objFSO.CopyFile or ultimately determine if the line in the textfile is a file or a folder by using objFSO.FileExists(file) or objFSO.FolderExists(file) checks before using copyfile or copyfolder.Wed, 08 Jul 2009 07:43:45 Z2009-07-08T07:43:45Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#dddec61b-52f7-4811-baf6-4262c7a28d0ehttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#dddec61b-52f7-4811-baf6-4262c7a28d0eAbqBillhttp://social.technet.microsoft.com/Profile/en-US/?user=AbqBillGet RoboCopy to read list of files to copy from a text fileHi Mike,<br/><br/>Are you saying that you want to replicate a folder structure, but not copy any files?<br/><br/>BillWed, 08 Jul 2009 14:12:26 Z2009-07-08T14:12:26Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#67996647-d3a7-4f67-94c0-23ac590dfae8http://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#67996647-d3a7-4f67-94c0-23ac590dfae8Mike2010http://social.technet.microsoft.com/Profile/en-US/?user=Mike2010Get RoboCopy to read list of files to copy from a text fileHi,<br/><br/>Sorry for not being clear, what i need is the list.txt to have folder names as well as file names that need to be copied across. The script from the above thread looks like it will crack it.<br/><br/>Many Thanks to everyone who helped out on this.<br/><br/>MikeThu, 09 Jul 2009 09:45:04 Z2009-07-09T09:45:04Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#e594851e-d169-4711-81c9-8ae53f318dedhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#e594851e-d169-4711-81c9-8ae53f318dedBrian Borghttp://social.technet.microsoft.com/Profile/en-US/?user=Brian%20BorgGet RoboCopy to read list of files to copy from a text file<blockquote>Hi,<br/><br/>Sorry for not being clear, what i need is the list.txt to have folder names as well as file names that need to be copied across. The script from the above thread looks like it will crack it.<br/><br/>Many Thanks to everyone who helped out on this.<br/><br/>Mike</blockquote> <br/>So would a variation on my oneliner:<br/><br/>&gt; For /f %%f in (list.txt) do xcopy &quot;c:\source\%%f&quot; d:\dest [switches]<br/><br/>The quotes would only be necessary if any of the file or folder names include spaces.<br/><br/>Typical switches:<br/><br/>  /C           Continues copying even if errors occur.<br/>  /I           If destination does not exist and copying more than one file,<br/>               assumes that destination must be a directory.<br/>  /H           Copies hidden and system files also.<br/>  /R           Overwrites read-only files.<br/>  /Y           Suppresses prompting to confirm you want to overwrite an<br/>               existing destination file.Thu, 09 Jul 2009 23:00:11 Z2009-07-09T23:00:11Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#84b5c3eb-a35e-484f-9c2e-58bda1a7a27ahttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#84b5c3eb-a35e-484f-9c2e-58bda1a7a27aHari Kodungallurhttp://social.technet.microsoft.com/Profile/en-US/?user=Hari%20KodungallurGet RoboCopy to read list of files to copy from a text fileHello,<br/> <br/> I need to do something that is almost similar to what is being discussed in this thread. So I am posting the question here (Apologies if I should have started another thread).<br/> <br/> Details of my requirement:<br/> - I already use robocopy to sync a large number of binary files. I use robocopy obviously because I want to copy only the files that are changed since the last copy. (something like rsync)<br/> - Almost always I can run the robocopy on the top level directory. But once in a while (very infrequently), I need to copy a few files (~100 files) from 3-4 directories. I do not want to copy anything else. Again, not all files within these 3-4 directories have changed. But I know that the files that have changed are within these directories. So again using robocopy will be ideal because it will copy only the changed files.<br/> <br/> From what I see so far, there is no way to provide just these directory names to robocopy and copy the appropriate files. I will have to loop through these directories and then robocopy individual files. Is that correct?<br/> <br/> <br/> thanks very much,<br/> -HariTue, 14 Jul 2009 00:02:26 Z2009-07-14T00:02:26Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#e3177c1a-eae7-41be-9a1b-63191b708452http://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#e3177c1a-eae7-41be-9a1b-63191b708452AbqBillhttp://social.technet.microsoft.com/Profile/en-US/?user=AbqBillGet RoboCopy to read list of files to copy from a text fileHi Hari,<br/> <br/> Yes, please start a new thread.<br/> <br/> Thanks,<br/> <br/> BillTue, 14 Jul 2009 00:31:49 Z2009-07-14T00:31:49Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#cc6b45e3-e4ec-4aab-a1dd-c2761928d4f4http://social.technet.microsoft.com/Forums/en/ITCG/thread/e7ac9618-e9f4-49f8-878c-0c2f61ac8922#cc6b45e3-e4ec-4aab-a1dd-c2761928d4f4Hari Kodungallurhttp://social.technet.microsoft.com/Profile/en-US/?user=Hari%20KodungallurGet RoboCopy to read list of files to copy from a text fileHello Bill,<br/> <br/> OK. Done. http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/07a82e5e-aa3b-40cf-8202-0433dc467564<br/> <br/> Thank you,<br/> -HariTue, 14 Jul 2009 00:53:27 Z2009-07-14T00:53:27Z