0

我正在编写一个编码的 ui 测试,该测试将作用于每晚创建的文件夹。我希望它工作的方式是测试将选择最新的文件夹。

我该怎么做?断言?

该文件夹是从我使用主应用程序打开的文件夹对话框中选择的。然后将文件夹的名称放入主应用程序的文本框中并扫描补丁。

 //Expand 'Computer' -> 'network drive (X:)' -> 'great-granparent' -> 'granparent' -> 'parent' -> 'folder' tree item
 uIfolder_TreeItem.Expanded = this.Browse_For_FolderParams.UIfolder_TreeItemExpanded;

使用 nXu 的代码我试过这个:

 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);

结束代码

        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;

谢谢您的帮助 :)

4

1 回答 1

3

使用DirectoryInfo 类,它具有 CreationTime、LastAccessTime 和 LastWriteTime 属性。例如,要选择 C:\ root 上最后创建的文件夹,请使用以下代码:

DirectoryInfo root = new DirectoryInfo(@"C:\");
DirectoryInfo[] folders = root.GetDirectories();

DirectoryInfo max = folders[0];
foreach (var dir in folders)
{
    if (dir.CreationTime.CompareTo(max.CreationTime) > 0)
        max = dir;
}

// Last created directory is max
于 2012-06-29T11:21:22.407 回答