Page 1 of 2
File or folder selected in windows explorer
Posted: Wed May 15, 2019 2:35 pm
by Kwai chang caine
Hello at all
Have you a way for knowing the path of the file or directory selected in windows explorer
Have a good day
Re: File or folder selected in windows explorer
Posted: Wed May 15, 2019 3:10 pm
by IdeasVacuum
Re: File or folder selected in windows explorer
Posted: Wed May 15, 2019 3:14 pm
by RSBasic
The code shows only the open folder windows, but not which folders and files are selected in the folder window.
Re: File or folder selected in windows explorer
Posted: Wed May 15, 2019 5:40 pm
by Kwai chang caine
Thanks at you two for your quick answer
Apparently it's a simple question, me too at the begining of my search, I'm sure it's very simple to have this information
But after several hours of search, i have not fount it
GetForegroundWindow_() return the handle of the windows explorer window, but for have the highlight file in this window, it's another pair of sleeves
If nobody know this tips, perhaps someone know how obtain the path of the element clicked and obviously immediatly hightlighing
Re: File or folder selected in windows explorer
Posted: Wed May 15, 2019 6:02 pm
by ar-s
I think GetForegroundWindow_() just return the name of the open windows, not the path.
Re: File or folder selected in windows explorer
Posted: Wed May 15, 2019 6:22 pm
by Kwai chang caine
Hello ARS
Yes it return the handle of the explorer Window
Re: File or folder selected in windows explorer
Posted: Wed May 15, 2019 6:34 pm
by Kwai chang caine
Thanks to RASHAD code i have make that
Code: Select all
Prototype.l ProtoAccessibleObjectFromPoint(x.l, y.l, *ia, *var)
Global AccessibleObjectFromPoint.ProtoAccessibleObjectFromPoint
CoInitialize_(0)
hdll.l = OpenLibrary(#PB_Any, "Oleacc.dll")
AccessibleObjectFromPoint = GetFunction(hdll, "AccessibleObjectFromPoint")
Repeat
Delay(100)
Define CursorPos.point, vt.VARIANT, *pIAcc.IAccessible, pName.l,len.l
GetCursorPos_(@CursorPos)
If AccessibleObjectFromPoint(CursorPos\x, CursorPos\y, @*pIAcc, @vt) = #S_OK
If *pIAcc\get_accValue(vt, @pName) = #S_OK And pName
Debug PeekS(pName)
EndIf
*pIAcc\Release()
EndIf
ForEver
Now i can read under mouse.....
But like the first question...how can i have the file or folder selected if i have the handle of the windows explorer window ?
Re: File or folder selected in windows explorer
Posted: Wed May 15, 2019 9:39 pm
by Little John
As far as I can see, the following works fine here on Windows 10.
1) Save
this code by Raymond Chen to a file, say "expl.js".
2) In the code, replace both characters “ and ” with "" (= Chr(34)).
3) Open an Explorer window and select one or more items in it.
4) Open a console window, and run this command:
I'm sure someone here can translate that JavaScript code to PB code.
Re: File or folder selected in windows explorer
Posted: Thu May 16, 2019 11:02 am
by Kwai chang caine
Hello LittleJohn
Thanks for your answer
I have try your tip and i have the answer
Console wrote:They are not script motor for the file extension ".js"
Re: File or folder selected in windows explorer
Posted: Thu May 16, 2019 11:09 am
by Kwai chang caine
But thanks to you and your idea, i have search in the direction of VbScript
I prefer PB and API solution, but for the moment this works
Code: Select all
Function GetSelectedFiles() 'Returns paths as array of strings
Dim FileList, Window, SelectedItem
'avoid duplicates by storing paths in dictionary keys
Set FileList = CreateObject("Scripting.Dictionary")
With CreateObject("Shell.Application")
For Each Window In .Windows
'skip IE Windows
If InStr(1, Window.FullName, "iexplore.exe", vbTextCompare) = 0 Then
For Each SelectedItem In Window.Document.SelectedItems
FileList(SelectedItem.Path) = Null
Next
End If
Next
End With
GetSelectedFiles = FileList.Keys 'array of paths
End Function
MsgBox "Click OK after selecting the items", _
vbOKOnly Or vbInformation, "Select a few items"
Dim SelectedFiles
SelectedFiles = GetSelectedFiles
MsgBox "You selected: " & vbNewLine & vbNewLine & _
Join(SelectedFiles, vbNewLine), vbOKOnly Or vbInformation, "Selected Items"
Again thanks LittleJohn for your precious help...you are a good man
Re: File or folder selected in windows explorer
Posted: Thu May 16, 2019 12:26 pm
by BarryG
Thank you too, Kwai chang caine, because your VBS script works perfectly for me too. Even when multiple files are selected in different folders, which amazed me!
Re: File or folder selected in windows explorer
Posted: Thu May 16, 2019 12:56 pm
by Kwai chang caine
Happy to read that !!!
for one time my search interesting someone
You can also use the great COMATE for run this VB code into PB
Even when multiple files are selected in different folders, which amazed me
Yes i have see that too, it's magic
It's a pity it's for the moment impossible with PB
your VBS script works perfectly for me too
It's not my code, i'm not enough intelligent to spawn that
It's Kul-Tigin code :
https://stackoverflow.com/questions/203 ... ected-file and LittleJohn for put me in one of the good ways
Thanks for your kind message
Re: File or folder selected in windows explorer
Posted: Fri May 17, 2019 8:27 am
by JHPJHP
Hi Kwai chang caine,
Kwai chang caine wrote:I prefer PB and API solution
...
It's a pity it's for the moment impossible with PB
NOTE: Most of the heavy lifting was done by
luis; see this
post.
-
Windows Services & Other Stuff
--
\Other_Stuff\SelectedItems\SelectedItems.pb
Re: File or folder selected in windows explorer
Posted: Fri May 17, 2019 9:37 am
by BarryG
JHPJHP, I don't know if it's my PC or what, but that codes takes a long time to get the selected files (about 2 seconds for each one). It also doesn't include the path to the file. By comparison, the VBS script is instant and includes the path.
Re: File or folder selected in windows explorer
Posted: Fri May 17, 2019 10:22 am
by JHPJHP
Hi BarryG,
BarryG wrote:the VBS script is instant and includes the path
Previous post has been updated to include the Path.
After some additional testing, if a selected file or folder is scrolled offscreen it may not be listed. This can definitely be resolved, but it requires more interest then I currently possess.
NB*: The script in its current form is still slower then the VB approach, but has the potential to do so much more.