CSharpTest.Net
CopyTo(String,Boolean) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > TempDirectory Class > CopyTo Method : CopyTo(String,Boolean) Method

target
replace

Glossary Item Box

Copies the directory content to the specified target directory name

Syntax

Visual Basic (Declaration) 
Public Overloads Sub CopyTo( _
   ByVal target As String, _
   ByVal replace As Boolean _
) 
C# 
public void CopyTo( 
   string target,
   bool replace
)

Parameters

target
replace

Example

Library/Library.Test/TestTempFiles.cs

C#Copy Code
using(TempDirectory a = new TempDirectory())
using(TempDirectory b = new TempDirectory())
{
    File.WriteAllText(Path.Combine(a.TempPath, "a.txt"), "text-a");
    Directory.CreateDirectory(Path.Combine(a.TempPath, "child"));
    File.WriteAllText(Path.Combine(a.TempPath, @"child\b.txt"), "text-b");

    a.CopyTo(b.TempPath);
    Assert.IsTrue(File.Exists(Path.Combine(b.TempPath, "a.txt")));
    Assert.AreEqual("text-a", File.ReadAllText(Path.Combine(b.TempPath, "a.txt")));
    Assert.IsTrue(File.Exists(Path.Combine(b.TempPath, @"child\b.txt")));
    Assert.AreEqual("text-b", File.ReadAllText(Path.Combine(b.TempPath, @"child\b.txt")));

    File.WriteAllText(Path.Combine(a.TempPath, @"child\b.txt"), "text-b-new");
    a.CopyTo(b.TempPath, true);
    //has changed
    Assert.AreEqual("text-b-new", File.ReadAllText(Path.Combine(b.TempPath, @"child\b.txt")));
}
VB.NETCopy Code
Using a As New TempDirectory()
    Using b As New TempDirectory()
        File.WriteAllText(Path.Combine(a.TempPath, "a.txt"), "text-a")
        Directory.CreateDirectory(Path.Combine(a.TempPath, "child"))
        File.WriteAllText(Path.Combine(a.TempPath, "child\b.txt"), "text-b")

        a.CopyTo(b.TempPath)
        Assert.IsTrue(File.Exists(Path.Combine(b.TempPath, "a.txt")))
        Assert.AreEqual("text-a", File.ReadAllText(Path.Combine(b.TempPath, "a.txt")))
        Assert.IsTrue(File.Exists(Path.Combine(b.TempPath, "child\b.txt")))
        Assert.AreEqual("text-b", File.ReadAllText(Path.Combine(b.TempPath, "child\b.txt")))

        File.WriteAllText(Path.Combine(a.TempPath, "child\b.txt"), "text-b-new")
        a.CopyTo(b.TempPath, True)
        'has changed
        Assert.AreEqual("text-b-new", File.ReadAllText(Path.Combine(b.TempPath, "child\b.txt")))
    End Using
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys