UI 自动化/检索文件扩展名

发布于 2024-08-28 11:56:37 字数 339 浏览 7 评论 0原文

我的任务是从一个文件夹中检索特定文件,在该文件夹中我只能在屏幕上获取 X 和 Y。虽然在XP中我设法利用Windows资源管理器本质上是一个列表视图这一事实,并使用WM_HITTEST消息来获取有关文件的信息,但在Windows 7中,情况并非如此。

为了解决这个问题,我使用了 UI Automation,这是一个很棒的工具,唯一的问题是在这种情况下,我正在查看的窗口句柄属于桌面,并且桌面可能有多个具有相同内容的文件名称但具有不同的扩展名(并且 Windows 配置为“隐藏已知文件类型的扩展名”)UI 自动化不会将扩展名返回给我。我尝试了很多方法,但找不到任何可靠的解决方案可以让我 100% 成功。

有人试过这个吗?成功地?

I am tasked with a project that requires me to retrieve a specific file from a folder where I can only get an X and Y on the screen. While in XP I managed to use the fact that windows explorer is in essence a list view, and used the WM_HITTEST message to obtain information about the file, in Windows 7, this is not the case.

To solve this problem, I am using UI Automation, which is a great tool for such things, only problem is that in the case, the windows handle I am looking at belongs to the desktop, and the desktop might have several files with the same name but with different extensions (and windows is configured to "hide extensions of known file types") UI automation does not return the extension back to me. I have tried many things, but I cannot find any robust solution which would give me 100% success.

Has anyone tried this? successfully?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

负佳期 2024-09-04 11:56:37

您能否提供有关“文件夹中的特定文件”的更多详细信息?
您将使用什么规则来手动识别文件?

我不认为通过 GUI 是处理这种情况的最佳方法。
如果有任何东西可以用于识别存储在文件/文件夹系统中的文件,我会尝试通过后端。

一个简单的示例来说明。计算文件夹中包含的文本文件总数,并存储找到的所有 Excel 文件的路径。

Dim sFolder
Dim FSO, objFolder, objFile, objXLSList
Dim intTXTCount

sFolder = "C:\TEMP"

Set FSO = CreateObject("Scripting.FileSystemObject")
Set objXLSList = CreateObject("Scripting.Dictionary")

Set objFolder = FSO.GetFolder(sFolder)
intTXTCount = 0
For Each objFile In objFolder.Files
 If Regex_Test(objFile.Name, ".*\.[t,T][t,T][t,T]") Then
  intTXTCount = intTXTCount + 1
 End If
 If Regex_Test(objFile.Name, ".*\.[x,X][l,L][s,S]") Then
  objXLSList.Add objXLSList.Count, objFile.Name
 End If
Next

谢谢你,
阿尔伯特·加里耶夫
http://automation-beyond.com/

Could you provide more details regarding "a specific file from a folder"?
What rules would you use to identify a file manually?

I wouldn't say going through the GUI is the best way for such cases.
If there is anything, that you can use for recognition of a file, stored in the file/folder system, I would try going through the back-end.

A simple example to illustrate. Counting total number of text files contained in a folder, and storing a path of the all Excel files found.

Dim sFolder
Dim FSO, objFolder, objFile, objXLSList
Dim intTXTCount

sFolder = "C:\TEMP"

Set FSO = CreateObject("Scripting.FileSystemObject")
Set objXLSList = CreateObject("Scripting.Dictionary")

Set objFolder = FSO.GetFolder(sFolder)
intTXTCount = 0
For Each objFile In objFolder.Files
 If Regex_Test(objFile.Name, ".*\.[t,T][t,T][t,T]") Then
  intTXTCount = intTXTCount + 1
 End If
 If Regex_Test(objFile.Name, ".*\.[x,X][l,L][s,S]") Then
  objXLSList.Add objXLSList.Count, objFile.Name
 End If
Next

Thank you,
Albert Gareev
http://automation-beyond.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文