private void CreateDirectoryStructure(Pri.LongPath.DirectoryInfo directory) { if (!directory.Parent.Exists) { CreateDirectoryStructure(directory.Parent); } directory.Create(); }
public void TestCreateWithFileSecurity() { var tempLongPathFilename = uncDirectory.Combine(Path.GetRandomFileName()); var di = new DirectoryInfo(tempLongPathFilename); try { di.Create(new DirectorySecurity()); Assert.IsTrue(tempLongPathFilename.Exists()); } finally { di.Delete(); } }
public void TestReplaceIgnoreMergeWithReadonlyBackupPath() { var tempLongPathFilename = new StringBuilder(uncDirectory).Append(@"\").Append("filename.ext").ToString(); var tempBackupPathName = new StringBuilder(uncDirectory).Append(@"\readonly").ToString(); var di = new DirectoryInfo(tempBackupPathName); di.Create(); var attr = di.Attributes; di.Attributes = attr | FileAttributes.ReadOnly; var tempBackupLongPathFilename = new StringBuilder(tempBackupPathName).Append(@"\").Append("backup").ToString(); using (var fileStream = File.Create(tempLongPathFilename)) { fileStream.WriteByte(42); } var tempLongPathFilename2 = new StringBuilder(uncDirectory).Append(@"\").Append("filename2.ext").ToString(); using (var fileStream = File.Create(tempLongPathFilename2)) { fileStream.WriteByte(52); } try { const Boolean ignoreMetadataErrors = true; File.Replace(tempLongPathFilename, tempLongPathFilename2, tempBackupLongPathFilename, ignoreMetadataErrors); using (var fileStream = File.OpenRead(tempLongPathFilename2)) { Assert.AreEqual(42, fileStream.ReadByte()); } Assert.IsFalse(File.Exists(tempLongPathFilename)); Assert.IsTrue(File.Exists(tempBackupLongPathFilename)); } finally { di.Attributes = attr; if (File.Exists(tempLongPathFilename)) { File.Delete(tempLongPathFilename); } File.Delete(tempLongPathFilename2); File.Delete(tempBackupLongPathFilename); if (tempBackupPathName.Exists()) { Pri.LongPath.Directory.Delete(tempBackupPathName); } } }
public void TestCreate() { var tempLongPathFilename = uncDirectory.Combine(Path.GetRandomFileName()); var di = new DirectoryInfo(tempLongPathFilename); di.Create(); try { Assert.IsTrue(di.Exists); } finally { Pri.LongPath.Directory.Delete(tempLongPathFilename); } }