public void TestGetFileSystemInfos() { var path = ZspIOHelper.GetTempDirectory().CombineDirectory(Guid.NewGuid().ToString()).CheckCreate(); try { var p1 = path.CombineDirectory(@"a").CheckCreate(); path.CombineDirectory(@"b").CheckCreate(); var f1 = p1.CombineFile("1.txt"); f1.WriteAllText("1"); Assert.IsTrue(path.GetFileSystemInfos().Length == 2); Assert.IsTrue(path.GetFileSystemInfos(SearchOption.AllDirectories).Length == 3); Assert.IsTrue( path.GetFileSystemInfos(SearchOption.AllDirectories).Where(f => f is FileInfo).ToList().Count == 1); Assert.IsTrue( path.GetFileSystemInfos(SearchOption.AllDirectories) .Where(f => f is DirectoryInfo) .ToList() .Count == 2); } finally { path.SafeDelete(); } }
public void TestTilde() { // https://github.com/UweKeim/ZetaLongPaths/issues/24 var path1 = ZspIOHelper.GetTempDirectory().CombineDirectory(Guid.NewGuid().ToString()).CheckCreate(); var path2 = Directory.CreateDirectory(ZspPathHelper.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())); try { var p1 = path1.CombineDirectory(@"a~b").CheckCreate(); var p2 = Directory.CreateDirectory(ZspPathHelper.Combine(path2.FullName, @"a~b")).FullName; var f1 = p1.CombineFile("1.txt"); f1.WriteAllText("1"); var f2 = ZspPathHelper.Combine(p2, "1.txt"); File.WriteAllText(f2, "1"); foreach (var file in p1.GetFiles()) { Console.WriteLine(file.FullName); } foreach (var file in Directory.GetFiles(p2)) { Console.WriteLine(file); } } finally { path1.SafeDelete(); path2.Delete(true); } }
public void TestDriveLetter() { Assert.IsTrue(ZspIOHelper.DriveExists('C')); Assert.IsTrue(ZspIOHelper.DriveExists('c')); Assert.IsFalse(ZspIOHelper.DriveExists('Q')); Assert.IsFalse(ZspIOHelper.DriveExists('q')); }
public void TestMove() { var path = ZspIOHelper.GetTempDirectory().CombineDirectory(Guid.NewGuid().ToString()).CheckCreate(); try { var p1 = path.CombineDirectory(@"a").CheckCreate(); var p2 = path.CombineDirectory(@"b"); var f1 = p1.CombineFile("1.txt"); f1.WriteAllText("1"); AssertOwn.DoesNotThrow(() => p1.MoveTo(p2)); } finally { path.SafeDelete(); } }
public void TestMD5() { var tempRootFolder = ZspIOHelper.GetTempDirectory(); Assert.IsTrue(tempRootFolder.Exists); var tempFolderPath = tempRootFolder.CombineDirectory(Guid.NewGuid().ToString(@"N")); tempFolderPath.CheckCreate(); try { var file = tempFolderPath.CombineFile(@"one.txt"); file.WriteAllText(@"Franz jagt im komplett verwahrlosten Taxi quer durch Bayern."); var hash = file.MD5Hash(); Assert.AreEqual(hash, @"ba4b9da310763a91f8edc7c185a1e4bf"); } finally { tempFolderPath.Delete(true); } }
public static bool IsEmpty(this DirectoryInfo i) { return(ZspIOHelper.IsDirectoryEmpty(i)); }
public static string MD5Hash(this FileInfo i) { return(ZspIOHelper.CalculateMD5Hash(i.FullName)); }
public void TestGeneral() { var tempFolder = Environment.ExpandEnvironmentVariables("%temp%"); Assert.IsTrue(Directory.Exists(tempFolder)); var tempPath = ZspPathHelper.Combine(tempFolder, "ZspTest"); try { Directory.CreateDirectory(tempPath); Assert.IsTrue(Directory.Exists(tempPath)); var filePath = ZspPathHelper.Combine(tempPath, "text.zsp"); using (var textStream = new StreamWriter(new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write))) { textStream.WriteLine("Zeta Short Paths Extended testing..."); textStream.Flush(); } Assert.IsTrue(File.Exists(filePath)); var m = ZspIOHelper.GetFileLength(filePath); Assert.IsTrue(m > 0); Assert.IsTrue(m == new FileInfo(filePath).Length); Assert.IsTrue(File.Exists(@"c:\Windows\notepad.exe")); Assert.IsFalse(File.Exists(@"c:\dslfsdjklfhsd\kjsaklfjd.exe")); Assert.IsFalse(File.Exists(@"c:\ablage")); Assert.IsFalse(Directory.Exists(@"c:\Windows\notepad.exe")); Assert.IsTrue(Directory.Exists(@"c:\Windows")); Assert.IsTrue(Directory.Exists(@"c:\Windows\")); Assert.IsFalse(Directory.Exists(@"c:\fkjhskfsdhfjkhsdjkfhsdkjfh")); Assert.IsFalse(Directory.Exists(@"c:\fkjhskfsdhfjkhsdjkfhsdkjfh\")); // -- AssertOwn.DoesNotThrow(() => File.SetLastWriteTime(filePath, new DateTime(1986, 1, 1))); AssertOwn.DoesNotThrow(() => File.SetLastAccessTime(filePath, new DateTime(1987, 1, 1))); AssertOwn.DoesNotThrow(() => File.SetCreationTime(filePath, new DateTime(1988, 1, 1))); AssertOwn.DoesNotThrow(() => Directory.SetLastWriteTime(tempPath, new DateTime(1986, 1, 1))); AssertOwn.DoesNotThrow(() => Directory.SetLastAccessTime(tempPath, new DateTime(1987, 1, 1))); AssertOwn.DoesNotThrow(() => Directory.SetCreationTime(tempPath, new DateTime(1988, 1, 1))); var anotherFile = ZspPathHelper.Combine(tempPath, "test2.zsp"); File.WriteAllText(anotherFile, @"הצ�."); Assert.IsTrue(File.Exists(anotherFile)); var time = File.GetLastWriteTime(filePath); Assert.IsTrue(time > DateTime.MinValue); var l = ZspIOHelper.GetFileLength(anotherFile); Assert.IsTrue(l > 0); } finally { Directory.Delete(tempPath, true); } }