I’m writing a coded ui test that is to act on a folder created every night. The way I want it to work is that the test will choose the newest folder.
How would I do this? Assertions?
The folder is being selected from a folder dialog box that I open with the main application. The name of the folder is then placed into a text box on the main app and scaned for patches.
//Expand 'Computer' -> 'network drive (X:)' -> 'great-granparent' -> 'granparent' -> 'parent' -> 'folder' tree item
uIfolder_TreeItem.Expanded = this.Browse_For_FolderParams.UIfolder_TreeItemExpanded;
Using nXu’s code I’ve tried this:
DirectoryInfo root = new DirectoryInfo(@"X:\great-granparent\granparent\parent");
DirectoryInfo[] folders = root.GetDirectories();
DirectoryInfo newest = folders[0];
foreach (var dir in folders)
{
if (dir.CreationTime.CompareTo(newest.CreationTime) > 0)
newest = dir;
}
//Expand 'Computer' -> 'network drive (X:)' -> 'great-granparent' -> 'granparent' -> 'parent' -> 'folder' tree item
newest = this.Browse_For_FolderParams(newest);
End Code
DirectoryInfo root = new DirectoryInfo(@"X:\great-granparent\granparent\parent");
DirectoryInfo[] folders = root.GetDirectories();
DirectoryInfo newest = folders[0];
foreach (var dir in folders)
{
if (dir.CreationTime.CompareTo(newest.CreationTime) > 0)
newest = dir;
}
uIfolder_TreeItem.SearchProperties["Name"] = newest.Name;
//Expand 'Computer' -> 'network drive (X:)' -> 'great-granparent' -> 'granparent' -> 'parent' -> 'folder' tree item
uIfolder_TreeItem.Expanded = this.Get_FolderParams.UIfolder_TreeItemExpanded;
Thanks for the help 🙂
Use the DirectoryInfo class, it has CreationTime, LastAccessTime and LastWriteTime properties.
For example, to select the last created folder on C:\ root, use the following code: