Visual Basic (Declaration) | |
---|---|
Public Overloads Sub CopyTo( _ ByVal target As String, _ ByVal replace As Boolean _ ) |
Parameters
- target
- replace
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.NET | Copy 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 |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
Reference
TempDirectory ClassTempDirectory Members
Overload List