File or folder selected in windows explorer

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

File or folder selected in windows explorer

Post 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
ImageThe happiness is a road...
Not a destination
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: File or folder selected in windows explorer

Post by IdeasVacuum »

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: File or folder selected in windows explorer

Post by RSBasic »

The code shows only the open folder windows, but not which folders and files are selected in the folder window.
Image
Image
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: File or folder selected in windows explorer

Post by Kwai chang caine »

Thanks at you two for your quick answer 8)

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 :oops:
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 :idea:
ImageThe happiness is a road...
Not a destination
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 340
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Re: File or folder selected in windows explorer

Post by ar-s »

I think GetForegroundWindow_() just return the name of the open windows, not the path.
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: File or folder selected in windows explorer

Post by Kwai chang caine »

Hello ARS :wink:
Yes it return the handle of the explorer Window
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: File or folder selected in windows explorer

Post by Kwai chang caine »

Thanks to RASHAD code i have make that :D

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 ? :|
ImageThe happiness is a road...
Not a destination
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: File or folder selected in windows explorer

Post 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:

Code: Select all

cscript <path>\expl.js
I'm sure someone here can translate that JavaScript code to PB code.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: File or folder selected in windows explorer

Post by Kwai chang caine »

Hello LittleJohn :D
Thanks for your answer 8)

I have try your tip and i have the answer
Console wrote:They are not script motor for the file extension ".js"
:|
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: File or folder selected in windows explorer

Post by Kwai chang caine »

But thanks to you and your idea, i have search in the direction of VbScript :idea:
I prefer PB and API solution, but for the moment this works 8)

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 8) :wink:
ImageThe happiness is a road...
Not a destination
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: File or folder selected in windows explorer

Post 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!
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: File or folder selected in windows explorer

Post by Kwai chang caine »

Happy to read that !!! :D for one time my search interesting someone :lol:
You can also use the great COMATE for run this VB code into PB 8)
Even when multiple files are selected in different folders, which amazed me
Yes i have see that too, it's magic :shock:
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 :mrgreen:
It's Kul-Tigin code : https://stackoverflow.com/questions/203 ... ected-file and LittleJohn for put me in one of the good ways 8)

Thanks for your kind message 8)
ImageThe happiness is a road...
Not a destination
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: File or folder selected in windows explorer

Post 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
Last edited by JHPJHP on Sat May 18, 2019 5:27 pm, edited 7 times in total.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: File or folder selected in windows explorer

Post 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.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: File or folder selected in windows explorer

Post 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.
Post Reply