public void ファイルを移動する() { PathInfo startupPath = new PathInfo(System.Windows.Forms.Application.StartupPath); PathInfo path = startupPath.Combine("test.conf"); PathInfo copyPath = startupPath.Combine("copytest.conf"); PathInfo movePath = startupPath.Combine("movetest.conf"); try { path.Copy(copyPath); copyPath.Move(movePath); Assert.AreEqual(PathInfo.PathType.UnExists, copyPath.Type); Assert.AreEqual(PathInfo.PathType.File, movePath.Type); } finally { if (copyPath.Type != PathInfo.PathType.UnExists) { copyPath.Delete(); } if (movePath.Type != PathInfo.PathType.UnExists) { movePath.Delete(); } } }
public void ディレクトリをコピーする() { PathInfo startupPath = new PathInfo(System.Windows.Forms.Application.StartupPath); PathInfo newDirectory1 = startupPath.Combine("NewDirectory1"); PathInfo newDirectory1InFile = newDirectory1.Combine("NewDirectory1File.txt"); PathInfo newDirectory2 = startupPath.Combine("NewDirectory2"); PathInfo newDirectory2InFile = newDirectory2.Combine("NewDirectory1File.txt"); try { System.IO.Directory.CreateDirectory(newDirectory1.FullPath); using (System.IO.File.Create(newDirectory1InFile.FullPath)) { } newDirectory1.Copy(newDirectory2); Assert.AreEqual(PathInfo.PathType.Directory, newDirectory2.Type); Assert.AreEqual(PathInfo.PathType.File, newDirectory2InFile.Type); } finally { if (newDirectory1.Type != PathInfo.PathType.UnExists) { newDirectory1.Delete(); } if (newDirectory2.Type != PathInfo.PathType.UnExists) { newDirectory2.Delete(); } } }
public void ファイルが削除される() { PathInfo startupPath = new PathInfo(System.Windows.Forms.Application.StartupPath); PathInfo copyPath = startupPath.Combine("testForCopy.conf"); startupPath.Combine("test.conf").Copy(copyPath); Assert.AreEqual(PathInfo.PathType.File, copyPath.Type); copyPath.Delete(); Assert.AreEqual(PathInfo.PathType.UnExists, copyPath.Type); }
public void ディレクトリが削除される() { PathInfo startupPath = new PathInfo(System.Windows.Forms.Application.StartupPath); PathInfo copyPath = startupPath.Combine("frameworkForCopy"); startupPath.Combine("framework").Copy(copyPath); Assert.AreEqual(PathInfo.PathType.Directory, copyPath.Type); copyPath.Delete(); Assert.AreEqual(PathInfo.PathType.UnExists, copyPath.Type); }
public void 連結したパスが取得できる() { PathInfo target = new PathInfo(System.Windows.Forms.Application.StartupPath); PathInfo actual = target.Combine("A", "test.conf"); string path = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "A","test.conf"); Assert.AreEqual(path, actual.FullPath); }
/// <summary> /// 指定したファイルパスにコピーします /// </summary> /// <param name="destination">コピー先のファイル</param> public void Copy(PathInfo destination) { if (this.Type == PathType.File) { File.Copy(this.FullPath, destination.FullPath); } else if (this.Type == PathType.Directory) { //コピー先のディレクトリがないときは作る if (destination.Type == PathType.UnExists) { System.IO.Directory.CreateDirectory(destination.FullPath); //属性もコピー System.IO.File.SetAttributes(destination.FullPath, System.IO.File.GetAttributes(this.FullPath)); } foreach (PathInfo path in this.GetChildren()) { path.Copy(destination.Combine(path.Name)); } } }