<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Using the FOR command to copy files listed in a text file</title>
	<atom:link href="http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/</link>
	<description>Thoughts on life, liberty, and information technology</description>
	<lastBuildDate>Tue, 24 Jan 2012 10:43:34 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Adrian</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-828185</link>
		<dc:creator>Adrian</dc:creator>
		<pubDate>Mon, 27 Jun 2011 07:48:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-828185</guid>
		<description>Thank you very much for such a useful script, i&#039;ve been looking for it for 2 days, but i have a problem

in my filelist.txt i have listed a lot of files with special characters, like á é í ó ú so it keeps telling

me file not found because it cannot read any of those characters, is there any way to fix this problem?

i really need to get over this, i have like 10 files listing me 200 files each one, it would take me

years to do it manually :S</description>
		<content:encoded><![CDATA[<p>Thank you very much for such a useful script, i&#8217;ve been looking for it for 2 days, but i have a problem</p>
<p>in my filelist.txt i have listed a lot of files with special characters, like á é í ó ú so it keeps telling</p>
<p>me file not found because it cannot read any of those characters, is there any way to fix this problem?</p>
<p>i really need to get over this, i have like 10 files listing me 200 files each one, it would take me</p>
<p>years to do it manually :S</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PatrickMc</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-588022</link>
		<dc:creator>PatrickMc</dc:creator>
		<pubDate>Tue, 26 Jan 2010 20:46:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-588022</guid>
		<description>Nice problem and solution. Can a scripting langugage such as biterscripting make the task easy ? Here is a script.


# Script CopyFiles.txt
var str src, dest, list, file
cat &quot;/path/to/list file.txt&quot; &gt; $list
lex &quot;1&quot; $list &gt; $file
while ($file  &quot;&quot;)
do
    system copy (&quot;\&quot;&quot;+$src+&quot;/&quot;+$file) (&quot;\&quot;&quot;+$dest+&quot;/&quot;+$file)
    lex &quot;1&quot; $list &gt; $file
done

This script is in biterscripting ( http://www.biterscripting.com ). Save the script in file C:/Scripts/CopyFiles.txt. Call the script using the following command.

script &quot;C:/Scripts/CopyFiles.txt&quot; src(&quot;/path/to/source folder&quot;) dest(&quot;/path/to/destination folder&quot;)</description>
		<content:encoded><![CDATA[<p>Nice problem and solution. Can a scripting langugage such as biterscripting make the task easy ? Here is a script.</p>
<p># Script CopyFiles.txt<br />
var str src, dest, list, file<br />
cat &#8220;/path/to/list file.txt&#8221; &gt; $list<br />
lex &#8220;1&#8243; $list &gt; $file<br />
while ($file  &#8220;&#8221;)<br />
do<br />
    system copy (&#8220;\&#8221;"+$src+&#8221;/&#8221;+$file) (&#8220;\&#8221;"+$dest+&#8221;/&#8221;+$file)<br />
    lex &#8220;1&#8243; $list &gt; $file<br />
done</p>
<p>This script is in biterscripting ( <a href="http://www.biterscripting.com" rel="nofollow">http://www.biterscripting.com</a> ). Save the script in file C:/Scripts/CopyFiles.txt. Call the script using the following command.</p>
<p>script &#8220;C:/Scripts/CopyFiles.txt&#8221; src(&#8220;/path/to/source folder&#8221;) dest(&#8220;/path/to/destination folder&#8221;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brian</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-584753</link>
		<dc:creator>brian</dc:creator>
		<pubDate>Thu, 14 Jan 2010 17:52:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-584753</guid>
		<description>If your filelist.txt has the full path to the files, you need to do two things:

1. Remove any path prefix to the source parameter of the xcopy command.
2. Remove the first slash in the UNC path in the destination parameter of the xcopy command.

Fortunately the command shell in Windows allows you to specify a substring of characters from a variable (called string indexing, see http://www.dostips.com/DtTipsStringManipulation.php). If the variable %i was your full UNC path, and you want to drop the first character (so you don&#039;t have a double-slash in your path), you can specify %i:~1 -- the :~1 says &quot;start from the second character&quot; (strings are zero-indexed, so the first character is at position 0, the second at position 1, etc.).

Your command line can then be:

for /f &quot;delims=&quot; %%i in (filelist.txt) do ( set fil=%%i
	echo D&#124;xcopy &quot;%%i&quot; &quot;c:\temp\%fil:~1%&quot; /i /z /y )

You have to set a temporary variable (&quot;fil&quot; in the above), since as far as I can tell string indexing doesn&#039;t work with the %%i for loop variable.</description>
		<content:encoded><![CDATA[<p>If your filelist.txt has the full path to the files, you need to do two things:</p>
<p>1. Remove any path prefix to the source parameter of the xcopy command.<br />
2. Remove the first slash in the UNC path in the destination parameter of the xcopy command.</p>
<p>Fortunately the command shell in Windows allows you to specify a substring of characters from a variable (called string indexing, see <a href="http://www.dostips.com/DtTipsStringManipulation.php)" rel="nofollow">http://www.dostips.com/DtTipsStringManipulation.php)</a>. If the variable %i was your full UNC path, and you want to drop the first character (so you don&#8217;t have a double-slash in your path), you can specify %i:~1 &#8212; the :~1 says &#8220;start from the second character&#8221; (strings are zero-indexed, so the first character is at position 0, the second at position 1, etc.).</p>
<p>Your command line can then be:</p>
<p>for /f &#8220;delims=&#8221; %%i in (filelist.txt) do ( set fil=%%i<br />
	echo D|xcopy &#8220;%%i&#8221; &#8220;c:\temp\%fil:~1%&#8221; /i /z /y )</p>
<p>You have to set a temporary variable (&#8220;fil&#8221; in the above), since as far as I can tell string indexing doesn&#8217;t work with the %%i for loop variable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lester</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-582152</link>
		<dc:creator>Lester</dc:creator>
		<pubDate>Mon, 04 Jan 2010 21:03:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-582152</guid>
		<description>Hi,

How I have a problem, the filelist.txt that i&#039;ve created constains different locations (server locations), 
\\server1\temp1
\\server2\temp2
\\server3\temp3
Can this be done using your batch file?

thanks,</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>How I have a problem, the filelist.txt that i&#8217;ve created constains different locations (server locations),<br />
\\server1\temp1<br />
\\server2\temp2<br />
\\server3\temp3<br />
Can this be done using your batch file?</p>
<p>thanks,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joel Eade</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-518213</link>
		<dc:creator>Joel Eade</dc:creator>
		<pubDate>Tue, 21 Jul 2009 12:38:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-518213</guid>
		<description>You&#039;ve saved me sooo much time! &quot;Thank You&quot; can&#039;t begin to explain my gratitude. You&#039;re awesome :)</description>
		<content:encoded><![CDATA[<p>You&#8217;ve saved me sooo much time! &#8220;Thank You&#8221; can&#8217;t begin to explain my gratitude. You&#8217;re awesome <img src='http://www.sidesofmarch.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Lim</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-512729</link>
		<dc:creator>David Lim</dc:creator>
		<pubDate>Tue, 14 Jul 2009 03:37:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-512729</guid>
		<description>Brian,

You are a genius!  I have been trying to do this all night without success and am glad that I found this site.  Thank you!!!

Keep up the good work.

David</description>
		<content:encoded><![CDATA[<p>Brian,</p>
<p>You are a genius!  I have been trying to do this all night without success and am glad that I found this site.  Thank you!!!</p>
<p>Keep up the good work.</p>
<p>David</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sari</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-376319</link>
		<dc:creator>Sari</dc:creator>
		<pubDate>Thu, 18 Dec 2008 09:55:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-376319</guid>
		<description>Thanks Brian! This was exactly what I was trying to do. Years ago I did a lot with DOS batch files and now I can not remember how to do it since dragging and dropping everything.
I modified your example a bit to create a text file listing files, which were not found.</description>
		<content:encoded><![CDATA[<p>Thanks Brian! This was exactly what I was trying to do. Years ago I did a lot with DOS batch files and now I can not remember how to do it since dragging and dropping everything.<br />
I modified your example a bit to create a text file listing files, which were not found.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-344256</link>
		<dc:creator>Josh</dc:creator>
		<pubDate>Wed, 12 Nov 2008 15:23:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-344256</guid>
		<description>Tried copy and it just bombed out.  I then put a pause at the end of the batch file so I could see exactly what it was doing.  The issue with the xcopy wound up being that it was set for Directory instead of File so I changed D&#124; to F&#124; before the xcopy thus making the script:

for /f “delims=” %%I in (test.txt) do echo F&#124; xcopy “C:\Documents and Settings\e1000721\Desktop\New\%%I” “C:\Copy\%%I”

Thanks again for the great help.</description>
		<content:encoded><![CDATA[<p>Tried copy and it just bombed out.  I then put a pause at the end of the batch file so I could see exactly what it was doing.  The issue with the xcopy wound up being that it was set for Directory instead of File so I changed D| to F| before the xcopy thus making the script:</p>
<p>for /f “delims=” %%I in (test.txt) do echo F| xcopy “C:\Documents and Settings\e1000721\Desktop\New\%%I” “C:\Copy\%%I”</p>
<p>Thanks again for the great help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brian</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-343693</link>
		<dc:creator>brian</dc:creator>
		<pubDate>Wed, 12 Nov 2008 02:13:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-343693</guid>
		<description>Try replacing xcopy with a regular copy command -- it might do the trick. (For some reason xcopy is defaulting to behavior assuming that the destination is a directory, not a file. Usually this only happens when the /I  switch is present.)</description>
		<content:encoded><![CDATA[<p>Try replacing xcopy with a regular copy command &#8212; it might do the trick. (For some reason xcopy is defaulting to behavior assuming that the destination is a directory, not a file. Usually this only happens when the /I  switch is present.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh</title>
		<link>http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-343478</link>
		<dc:creator>Josh</dc:creator>
		<pubDate>Tue, 11 Nov 2008 23:29:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.sidesofmarch.com/index.php/archive/2004/03/30/using-the-for-command-to-copy-files-listed-in-a-text-file/#comment-343478</guid>
		<description>I appear to be having the same issue as Joe.

Before running this in my live environment, I decided to test it first.

My bat file states:
for /f &quot;delims=&quot; %%I in (test.txt) do echo D&#124; xcopy &quot;C:\Documents and Settings\e1000721\Desktop\New\%%I&quot; &quot;C:\Copy\%%I&quot;

My test.txt file states
Level\test\File1.txt
Level\test\File2.txt
test\File3.txt
test\File4.txt

And it does copy over fine, only when it finishes, the file structure appears as
C:\Copy\Level\test\File1.txt\File2.txt
C:\Copy\Level\test\File2.txt\File2.txt
C:\Copy\test\File3.txt\File3.txt
C:\Copy\test\File4.txt\File4.txt

Any thoughts on how I can get it to not make the last subfolder the name of the file?

Thanks.</description>
		<content:encoded><![CDATA[<p>I appear to be having the same issue as Joe.</p>
<p>Before running this in my live environment, I decided to test it first.</p>
<p>My bat file states:<br />
for /f &#8220;delims=&#8221; %%I in (test.txt) do echo D| xcopy &#8220;C:\Documents and Settings\e1000721\Desktop\New\%%I&#8221; &#8220;C:\Copy\%%I&#8221;</p>
<p>My test.txt file states<br />
Level\test\File1.txt<br />
Level\test\File2.txt<br />
test\File3.txt<br />
test\File4.txt</p>
<p>And it does copy over fine, only when it finishes, the file structure appears as<br />
C:\Copy\Level\test\File1.txt\File2.txt<br />
C:\Copy\Level\test\File2.txt\File2.txt<br />
C:\Copy\test\File3.txt\File3.txt<br />
C:\Copy\test\File4.txt\File4.txt</p>
<p>Any thoughts on how I can get it to not make the last subfolder the name of the file?</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

