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?
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/
精彩评论