<?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: C# Copy Folder Recursively</title>
	<atom:link href="http://www.csharp411.com/c-copy-folder-recursively/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.csharp411.com/c-copy-folder-recursively/</link>
	<description>C# Information, Code, Tips and News</description>
	<lastBuildDate>Sat, 24 Jul 2010 01:26:51 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Unknown</title>
		<link>http://www.csharp411.com/c-copy-folder-recursively/comment-page-1/#comment-5492</link>
		<dc:creator>Unknown</dc:creator>
		<pubDate>Thu, 20 May 2010 06:14:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-copy-folder-recursively/#comment-5492</guid>
		<description>you can check this post:
http://namita2021.wordpress.com/2010/05/07/system-io-directory-2/</description>
		<content:encoded><![CDATA[<p>you can check this post:<br />
<a href="http://namita2021.wordpress.com/2010/05/07/system-io-directory-2/" rel="nofollow">http://namita2021.wordpress.com/2010/05/07/system-io-directory-2/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amol</title>
		<link>http://www.csharp411.com/c-copy-folder-recursively/comment-page-1/#comment-5490</link>
		<dc:creator>Amol</dc:creator>
		<pubDate>Wed, 19 May 2010 13:21:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-copy-folder-recursively/#comment-5490</guid>
		<description>Many thanks....you saved my day</description>
		<content:encoded><![CDATA[<p>Many thanks&#8230;.you saved my day</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eitan</title>
		<link>http://www.csharp411.com/c-copy-folder-recursively/comment-page-1/#comment-5384</link>
		<dc:creator>Eitan</dc:creator>
		<pubDate>Tue, 16 Feb 2010 18:54:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-copy-folder-recursively/#comment-5384</guid>
		<description>You have two options, one is to use Directory.GetFileSystemEntries(,), and copy or create directory according to the entry type (this function returns files and folders as well).
The other option is to do first a loop for folders only by using Directory.GetDirectories(), and create the target folder if it does not exist, if you use this approach, you can remove the folder creation from the file loop.</description>
		<content:encoded><![CDATA[<p>You have two options, one is to use Directory.GetFileSystemEntries(,), and copy or create directory according to the entry type (this function returns files and folders as well).<br />
The other option is to do first a loop for folders only by using Directory.GetDirectories(), and create the target folder if it does not exist, if you use this approach, you can remove the folder creation from the file loop.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PKSpence</title>
		<link>http://www.csharp411.com/c-copy-folder-recursively/comment-page-1/#comment-5383</link>
		<dc:creator>PKSpence</dc:creator>
		<pubDate>Tue, 16 Feb 2010 15:29:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-copy-folder-recursively/#comment-5383</guid>
		<description>@Eitan... great solution, thanks! I noticed that it will not copy directories that are empty. Any way to get around that?</description>
		<content:encoded><![CDATA[<p>@Eitan&#8230; great solution, thanks! I noticed that it will not copy directories that are empty. Any way to get around that?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sarawut</title>
		<link>http://www.csharp411.com/c-copy-folder-recursively/comment-page-1/#comment-5378</link>
		<dc:creator>sarawut</dc:creator>
		<pubDate>Tue, 09 Feb 2010 02:59:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-copy-folder-recursively/#comment-5378</guid>
		<description>to Enrique: you can remove read-only flag on some files or directories  by using this

staticvoid setAttributesNormal(DirectoryInfo dir)
{
// Remove flags from the current directory
dir.Attributes = FileAttributes.Normal;

// Remove flags from all files in the current directory
foreach (FileInfo file in dir.GetFiles())
{
file.Attributes = FileAttributes.Normal;
}

// Do the same for all subdirectories
foreach (DirectoryInfo subDir in dir.GetDirectories())
{
setAttributesNormal(subDir);
} 
}


ref : http://msdn.microsoft.com/en-us/library/fxeahc5f.aspx</description>
		<content:encoded><![CDATA[<p>to Enrique: you can remove read-only flag on some files or directories  by using this</p>
<p>staticvoid setAttributesNormal(DirectoryInfo dir)<br />
{<br />
// Remove flags from the current directory<br />
dir.Attributes = FileAttributes.Normal;</p>
<p>// Remove flags from all files in the current directory<br />
foreach (FileInfo file in dir.GetFiles())<br />
{<br />
file.Attributes = FileAttributes.Normal;<br />
}</p>
<p>// Do the same for all subdirectories<br />
foreach (DirectoryInfo subDir in dir.GetDirectories())<br />
{<br />
setAttributesNormal(subDir);<br />
}<br />
}</p>
<p>ref : <a href="http://msdn.microsoft.com/en-us/library/fxeahc5f.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/fxeahc5f.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sarawut</title>
		<link>http://www.csharp411.com/c-copy-folder-recursively/comment-page-1/#comment-5377</link>
		<dc:creator>sarawut</dc:creator>
		<pubDate>Tue, 09 Feb 2010 02:32:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-copy-folder-recursively/#comment-5377</guid>
		<description>Great very helpful</description>
		<content:encoded><![CDATA[<p>Great very helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Enrique</title>
		<link>http://www.csharp411.com/c-copy-folder-recursively/comment-page-1/#comment-5366</link>
		<dc:creator>Enrique</dc:creator>
		<pubDate>Thu, 21 Jan 2010 16:33:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-copy-folder-recursively/#comment-5366</guid>
		<description>this creates a new readonly directory and files,
what if I want them to be read-write?

Thx</description>
		<content:encoded><![CDATA[<p>this creates a new readonly directory and files,<br />
what if I want them to be read-write?</p>
<p>Thx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Enrique</title>
		<link>http://www.csharp411.com/c-copy-folder-recursively/comment-page-1/#comment-5365</link>
		<dc:creator>Enrique</dc:creator>
		<pubDate>Thu, 21 Jan 2010 16:32:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-copy-folder-recursively/#comment-5365</guid>
		<description>This creates only readonly files and directories even if the destination directory is read-write,

how can I change to read-write all the permissions on this copied files and directories?</description>
		<content:encoded><![CDATA[<p>This creates only readonly files and directories even if the destination directory is read-write,</p>
<p>how can I change to read-write all the permissions on this copied files and directories?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eitan</title>
		<link>http://www.csharp411.com/c-copy-folder-recursively/comment-page-1/#comment-5337</link>
		<dc:creator>Eitan</dc:creator>
		<pubDate>Mon, 07 Dec 2009 07:04:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-copy-folder-recursively/#comment-5337</guid>
		<description>I wrote this using Linq (I don&#039;t like recursive functions):

public static void CopyAllFiles(string sourceFolder, string destinationFolder)
        {
            var FileList = from files in Directory.GetFiles(sourceFolder, &quot;*.*&quot;, SearchOption.AllDirectories)
                           select files;

            foreach (string file in FileList)
            {
                string RelativeFilePath = file.Replace(sourceFolder, &quot;&quot;);
                string DestinationFilePath = String.Format(&quot;{0}{1}{2}&quot;,
                    destinationFolder, Path.DirectorySeparatorChar, RelativeFilePath);

                if (!Directory.Exists(Path.GetDirectoryName(DestinationFilePath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(DestinationFilePath));
                }

                File.Copy(file, DestinationFilePath, true);
            }

        }</description>
		<content:encoded><![CDATA[<p>I wrote this using Linq (I don't like recursive functions):</p>
<p>public static void CopyAllFiles(string sourceFolder, string destinationFolder)<br />
        {<br />
            var FileList = from files in Directory.GetFiles(sourceFolder, "*.*", SearchOption.AllDirectories)<br />
                           select files;</p>
<p>            foreach (string file in FileList)<br />
            {<br />
                string RelativeFilePath = file.Replace(sourceFolder, "");<br />
                string DestinationFilePath = String.Format("{0}{1}{2}",<br />
                    destinationFolder, Path.DirectorySeparatorChar, RelativeFilePath);</p>
<p>                if (!Directory.Exists(Path.GetDirectoryName(DestinationFilePath)))<br />
                {<br />
                    Directory.CreateDirectory(Path.GetDirectoryName(DestinationFilePath));<br />
                }</p>
<p>                File.Copy(file, DestinationFilePath, true);<br />
            }</p>
<p>        }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DLZ</title>
		<link>http://www.csharp411.com/c-copy-folder-recursively/comment-page-1/#comment-5326</link>
		<dc:creator>DLZ</dc:creator>
		<pubDate>Mon, 09 Nov 2009 15:05:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-copy-folder-recursively/#comment-5326</guid>
		<description>This algorithm works fine if there is no parent-child relation between the source and destination directory.
If you pass a subdirectory as destination directory this algorithm doesn&#039;t take care of it. It will endlessly enumerate the newly created sub folders and makes further copies of them. 
If you pass a parent directory of source as destination the following happens: If the directory structure has any element which on the new destination path collides with the root of the source structure there will be undesired happenings: Overwrites or unsuccessful copies because of colliding filenames or duplicated copies.
I&#039;ll implement such procedure which get over these problems so this function basically right but have to be a little extended for my needs.</description>
		<content:encoded><![CDATA[<p>This algorithm works fine if there is no parent-child relation between the source and destination directory.<br />
If you pass a subdirectory as destination directory this algorithm doesn't take care of it. It will endlessly enumerate the newly created sub folders and makes further copies of them.<br />
If you pass a parent directory of source as destination the following happens: If the directory structure has any element which on the new destination path collides with the root of the source structure there will be undesired happenings: Overwrites or unsuccessful copies because of colliding filenames or duplicated copies.<br />
I'll implement such procedure which get over these problems so this function basically right but have to be a little extended for my needs.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
