public void GetCountOfSubdirectories() { try { if (!HasFolderPermission) { return; } Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path"); Assert.IsTrue(IoDir.CreateDirectory(TestFolder + "//"), "Error creating directory"); Assert.IsTrue(IoDir.DirectoryExists(TestFolder + "//"), "Error creating directory"); for (var d = 0; d < 5; d++) { IoDir.CreateDirectory(TestFolder + "//" + d + "//"); } Assert.IsTrue(IoDir.GetCountOfSubdirectories(TestFolder + "//") == 5, "Error counting subdirectories"); } finally { if (HasFolderPermission) { IoDir.DeleteDirectory(TestFolder + "//"); } } }
public void DeleteDirectoryContents() { try { if (!HasFolderPermission || !HasFilePermission) { return; } Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path"); Assert.IsTrue(IoDir.CreateDirectory(TestFolder + "//"), "Error creating directory"); Assert.IsTrue(IoDir.DirectoryExists(TestFolder + "//"), "Error creating directory"); for (var d = 0; d < 5; d++) { if (d == 0) { for (var i = 0; i < 20; i++) { IoFiles.CreateFile(TestFolder + "//" + i + ".txt", i.ToString(CultureInfo.InvariantCulture)); } } IoDir.CreateDirectory(TestFolder + "//" + d + "//"); for (var i = 0; i < 20; i++) { IoFiles.CreateFile(TestFolder + "//" + d + "//" + i + ".txt", i.ToString(CultureInfo.InvariantCulture)); } } var mainFilesCount = IoFiles.GetCountOfFilesInDirectoryAndSubdirectories(TestFolder + "//"); var mainFoldersCount = IoDir.GetCountOfSubdirectories(TestFolder + "//"); Assert.IsTrue(mainFilesCount > 0, "Error counting files on directory"); Assert.IsTrue(mainFoldersCount > 0, "Error counting subdirectories"); Console.WriteLine("Files count: {0}", mainFilesCount); Console.WriteLine("Subdirectories count: {0}", mainFoldersCount); Assert.IsTrue(IoDir.DeleteDirectoryContents(TestFolder + "//"), "Error deleting directory content"); mainFilesCount = IoFiles.GetCountOfFilesInDirectoryAndSubdirectories(TestFolder + "//"); mainFoldersCount = IoDir.GetCountOfSubdirectories(TestFolder + "//"); Console.WriteLine("\nFiles count: {0}", mainFilesCount); Console.WriteLine("Subdirectories count: {0}", mainFoldersCount); Assert.IsTrue(mainFilesCount == mainFoldersCount && mainFilesCount == 0, "Error deleting files and subdirectories"); } finally { if (HasFolderPermission) { IoDir.DeleteDirectory(TestFolder + "//"); } } }