views:

164

answers:

1

Dear all,

I am tasked with a project that requires me to retreieve 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?

Would appreciate any pointers.

Many thanks,

A: 

Hi AP,

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/

Albert Gareev
Hi Albert,thanks for the reply, I'm sorry but I cannot describe too much of the application, as I am bound by NDA's and such, however, what I can say, is that the approach you wrote, although it will work, cannot be used in my case.As I stated, what I receive is an X, Y and a handle to a window, from that I have to deduce what I am looking at. While UI automation can certainly give me a lot of information, it fails to give me information about the actual file system element I am looking at.
AP
Well, it doesn't look for me that "UI automation ... fails to give ... information about the actual file system element". Given that you only provide coordinates of a pixel it has nothing to do with a file system.What tool do you use? Can it return you a text using OCR or something else? If you can retrieve a name of a parent folder, and a name (even without extension), you can still loop through the collection of children.
Albert Gareev
Hi Albert - I am afraid OCR is something that cannot be used due to issues of processing time, development time and complexity... I have used the approach of looping through the files in the containing folder, but if I have several files with the same name, but with a different extension, and all I get from UI automation is the file name without the extension, all I have to go on is the index of the file in the list, and that's not 100% (it's the approach I'm using now) - what I'm looking for is an approach which would give me something which is a bit more robust...
AP