how to get file path

Discussion related to "Everything" 1.5 Alpha.
Post Reply
fantasynew
Posts: 11
Joined: Wed May 11, 2022 10:18 am

how to get file path

Post by fantasynew »

I want to develop a add-in about everything.
How to get the selected file path in everything?
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: how to get file path

Post by NotNull »

Sounds interesting! What will your add-in do?


What language? This is what I use in AutoHotKey:

In Everything 1.5 is a hidden control ( EVERYTHING_RESULT_LIST_FOCUS1) that contains the current path
In version 1.4 the path is copied to the clipboard using SendMessage

Code: Select all

	
;_____________________________________________________________________________
;
						GetPathFromEverything(_EverythingID)
;_____________________________________________________________________________
;
{
	Global $DoubleClickTime
	Global $majorversion
	Global $detected_everything_version

	$EVERYTHING_IPC_ID_FILE_COPY_FULL_PATH_AND_NAME := 41007	

	If ( $detected_everything_version == "1.5")
	{
		ControlGetText, _FoundPath, EVERYTHING_RESULT_LIST_FOCUS1, A
		DebugMsg( A_ThisLabel . A_ThisFunc, "detected_everything_version = [" . $detected_everything_version . "]`r`nFound path = [" . _FoundPath . "]" )
	}		
	Else If ( $detected_everything_version == "1.4")
	{
	;	DopusDebug
		Sleep %$slowdown%

		_ClipOrg := ClipBoard

	;	DopusDebug
		Sleep %$slowdown%

		ClipBoard := ""

	;	DopusDebug
		Sleep %$slowdown%

		SendMessage, 0x111, %$EVERYTHING_IPC_ID_FILE_COPY_FULL_PATH_AND_NAME%,,, A
		ClipWait,1
		_FoundPath := Clipboard

	;	DopusDebug
;		MsgBox _FoundPath = %_FoundPath%

		
		DebugMsg( A_ThisLabel . A_ThisFunc, "detected_everything_version = [" . $detected_everything_version . "]" . "`r`n" . "Found path = [" . _FoundPath . "]" )

	;	DopusDebug
		Sleep %$slowdown%

		ClipBoard := _ClipOrg
	}
	else	; should never happen
	{
		MsgBox Somehow this is not really Everything 1.4 or 1.5. Check your settings.
	}

	Return _FoundPath
}



In the past I used the following:
Get the current active row and read what is in column1 (Name) and column2 (Path) and glue those together
Requires that column 1 and 2 are indeed Name and Path (or the localized version thereof, like "Naam" and "Pad" in Dutch)

Code: Select all



	
;_____________________________________________________________________________
;
    GetSelection:
;_____________________________________________________________________________
;

;   We're here because an Enter was pressed in an Everything window.
;   Now we need to find out if it's "our" window (then talk to that window) or 
;   any other window (then feed it the {Enter} we caught)
;
;	If {Enter} was in the Everything search-bar , move focus to resultlist
;	Also: when an {Enter} was pressed in Everything's searchbar (ClassNN = Edit1)
;	to go to the results, feed a normal {Enter} (or {Tab} or {Down})
;	To detect, use ControlGetFocus, OutputVar [, WinTitle, WinText, ExcludeTitle, ExcludeText]


    If ( WinExist("A") = $EverythingID ) {            ; We found our window
;       Get currently selected row (the highlighted one when Enter was pressed)
        ControlGet, $Rows, List, Selected, SysListView321, ahk_id %$EverythingID%
;   	We got what we need; Everything window can be colsed
		Send {Escape}
	}

;	Check if this is a folder or file. If file: get folderpath
;   Make a FolderPath out of what we grabbed fromm Everything
	StringSplit, $Column, $Rows, %A_Tab% ; Fields are delimited by tabs (A_Tab)

;===> TEST
;	$FolderPath=%$Column2%\%$Column1%\ ; Path without "". End it with \
	$Result=%$Column2%\%$Column1% ; Path without "". End it with \
; Check if folder exists (off-line / no access)? Or let Windows handle it?
	IfNotExist, %$Result%
	{
		MsgBox, 48, %$Result%, File/folder not accessible. Off-line or no access?`n Please try a different folder.
		ExitApp
	}
;	$FolderPath=%$Column2%\%$Column1% ; Path without "". DO NOT End it with \
;<===TEST

;	MsgBox GetSelection: %$FolderPath%
;	Check if File or Folder
;	If folder: create $FolderPath
;	If file: create $FolderPath AND $FileName
;	Those will be used in the "Feed" routines (if applicable)

		if InStr(FileExist($Result), "D")
		{
			MsgBox It's a folder! : %$Result%
			$FolderPath := %$Result%
		}
		else
		{	MsgBox It's a file! : %$Column2%  \  %$Column1%
			$FolderPath=%$Column2%
			$FileName=%$Column1%
		}
return

fantasynew
Posts: 11
Joined: Wed May 11, 2022 10:18 am

Re: how to get file path

Post by fantasynew »

Thank you for reply!
20220531084632.png
20220531084632.png (18.95 KiB) Viewed 7173 times
As you say,I can get the path by WM_GETTEXT,but only one selected file path can be shown in the title.
I know this syslistview32 can be read by message,but it is not so clever.
The similar way to do this is call the context_menu and copy to clipboard.
……………………………………………………………………………………………………………………………………

The add-in just add tags and remarks to files with NTFS ADS,show the ADS and manage it.
I'm not a programmer,it may be difficult to do this.

……………………………………………………………………………………………………………………………………
20220531103007.png
20220531103007.png (2.55 KiB) Viewed 7170 times
Thank you!It's useful
raccoon
Posts: 1017
Joined: Thu Oct 18, 2018 1:24 am

Re: how to get file path

Post by raccoon »

What if you just use Everything to execute a batch file (or any custom script or software) with the selected items, allowing Windows to pass the path-and-filenames to your script. Then you just handle them as parameters. %1
fantasynew
Posts: 11
Joined: Wed May 11, 2022 10:18 am

Re: how to get file path

Post by fantasynew »

raccoon wrote: Tue May 31, 2022 2:42 am What if you just use Everything to execute a batch file (or any custom script or software) with the selected items, allowing Windows to pass the path-and-filenames to your script. Then you just handle them as parameters. %1
Not only script but also has another parameters
Skier
Posts: 6
Joined: Sun Apr 17, 2022 6:34 am

Re: how to get file path

Post by Skier »

I'm using the following code (AutoHotKey) to retrieve the full paths of the selected result list items from Everything. in SysListView321table Col1 is "file name.ext" Col3 is "path"

Code: Select all

F12::
sel1 := Path_Get_from_Everything()
msgbox, %sel1%
return
;--------------------------------------------------------------------------------------
Path_Get_from_Everything()
{
	WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
	WinGetClass class, ahk_id %hwnd%
	File_array:=[]
	Path_array:=[]
	total_num:=0
	ret := ""
	if (class= "EVERYTHING")
	{
		ControlGet, hwWindow, HWND,, SysListView321, A
		ControlGet, paths, List, Selected Col3,,ahk_id %hwWindow%
		ControlGet, files, List, Selected Col1,,ahk_id %hwWindow%

		Loop, Parse, files, `n, `r
		{
			File_array[A_Index] := A_LoopField
		}
		Loop, Parse, paths, `n, `r
		{
			total_num += 1
			Path_array[A_Index] := A_LoopField "\"
		}
		Loop %total_num%
		{
		path := path_array[A_Index] file_Array[A_Index]
		ret .= """" path """" " "
		path_array[A_Index] .= file_Array[A_Index]
		}
	}
	return ret
}
andymbody
Posts: 45
Joined: Fri Nov 25, 2022 7:40 am

Re: how to get file path

Post by andymbody »

@Skier

I have tried your ahk code but am unable to get the list of items from Everything app.

The following code does not seem to allow the lists to populate. I have tried many different things to debug the cause and it seems that the Everything app will not allow access to the SysListView321 control for some reason (or any other control for that matter). I can get a list to populate within other apps, but not the Everything app. I can get a list of controls within the Everything app, but am unable to access their properties or values. And this includes using the SendMessage commands (during debugging).

ControlGet, hwWindow, HWND,, SysListView321, A
ControlGet, paths, List, Selected Col3,,ahk_id %hwWindow%
ControlGet, files, List, Selected Col1,,ahk_id %hwWindow%

I am currently using AHK 1.1.26, running Everything 1.5a (as admin), on a Win7 laptop (yes, I know it's ancient). Any idea why this configuration would not allow your code to work? I wonder if something has changed within the Everything app recently or maybe it's related to using Win7?

Your thoughts?
Andy
Last edited by andymbody on Sat Nov 26, 2022 6:09 am, edited 1 time in total.
horst.epp
Posts: 1443
Joined: Fri Apr 04, 2014 3:24 pm

Re: how to get file path

Post by horst.epp »

The following AHK code is part of a script we use to get the current Everything search results
into a text file, for displaying it in Total Commander.

Code: Select all

hWnd := WinExist("ahk_exe Everything(?:\d\d)*\.exe")
if hWnd
{
  ControlGet, winContent, List, , SysListView321, % "ahk_id" hWnd

  if (winContent)
  {
    fullContent := ""
;   Loop over row(s)
    Loop, Parse, winContent, `n
    {

There is no problem using SyslistView321 in this context
and many poeple are using the full script without problems.
You can have the complete script if you want.

You should not run Everything in Admin mode as this may prevent your access.
andymbody
Posts: 45
Joined: Fri Nov 25, 2022 7:40 am

Re: how to get file path

Post by andymbody »

You should not run Everything in Admin mode as this may prevent your access
That was it! Am able to get contents of control now... Thank you!!
andymbody
Posts: 45
Joined: Fri Nov 25, 2022 7:40 am

Re: how to get file path

Post by andymbody »

You can have the complete script if you want.
That would be great... can you tell me where to find it?
Does it include code for extracting column header text?

UPDATE... never mind... I found it and now have a column header extractor and have added it to my project

Thanks!
Andy
Last edited by andymbody on Sat Nov 26, 2022 3:50 am, edited 1 time in total.
Ralf_Reddings
Posts: 120
Joined: Fri Mar 24, 2023 4:53 pm

Help with getting the current Everything selection using AHK please

Post by Ralf_Reddings »

I have been using this function by Skier from this thread how to get file path for about a day to get the currently selected objects:

Code: Select all

F1::
sel1 := Path_Get_from_Everything()
msgbox, %sel1%
return
;--------------------------------------------------------------------------------------
Path_Get_from_Everything()
{
    WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
    WinGetClass class, ahk_id %hwnd%
    File_array:=[]
    Path_array:=[]
    total_num:=0
    ret := ""
    if (class= "EVERYTHING")
    {
        ControlGet, hwWindow, HWND,, SysListView321, A
        ControlGet, paths, List, Selected Col3,,ahk_id %hwWindow%
        ControlGet, files, List, Selected Col1,,ahk_id %hwWindow%

        Loop, Parse, files, [c]n, [/c]r
        {
            File_array[A_Index] := A_LoopField
        }
        Loop, Parse, paths, [c]n, [/c]r
        {
            total_num += 1
            Path_array[A_Index] := A_LoopField "\"
        }
        Loop %total_num%
        {
        path := path_array[A_Index] file_Array[A_Index]
        ret .= """" path """" " "
        path_array[A_Index] .= file_Array[A_Index]
        }
    }
    return ret
}
Today I noticed it has a few short comings or perhaps I just assumed things. Essentially the functions seems to rely on the columns that are currently being being shown,

So if the name column is set to only show file names (via INI setting
/display_full_path_name
) the function returns:

Code: Select all

\Lazy Nezumi Key Editor.ahk
\Lazy Nezumi Preferences.ahk
\Delete 10 frames.ahk
\Delete 1 frame.ahk
If I also decide to flip INI setting
display_full_path_name
, I noticed the function is still misbehaving until I close the active window and open another one. Perhaps this hidden window does not notice
display_full_path_name=1
?

I did some more tests hiding showing various columns and the functions behaviour seems to be tied to active columns

The thing is I have allot of bookmarks that are constantly toggling columns as I work with a variety of files and sometimes I am not even concerned with paths/names so they are not even showing.

Is there a more reliable way to get the full paths of selected objects?

In the same thread I linked to above, user NotNull mentions:
>In version 1.4 the path is copied to the clipboard using SendMessage
Is this still possible with version 1.5?

Thank you.
void
Developer
Posts: 16671
Joined: Fri Oct 16, 2009 11:31 pm

Re: how to get file path

Post by void »

Perhaps this hidden window does not notice display_full_path_name=1 ?
Using a script to read the text from the listview will return the text as is.
This means the order of the columns and what columns are shown are important.

display_full_path_name will also control what is returned for the name column.

The listview window is not hidden.



The text of the hidden result list focus window is always the full path and filename.
It doesn't matter what display_full_path_name setting you are using.


Is there a more reliable way to get the full paths of selected objects?
>In version 1.4 the path is copied to the clipboard using SendMessage

Is this still possible with version 1.5?

Maybe the IPC call: UI_ID_FILE_COPY_FULL_PATH_AND_NAME (41007)

SendMessage(FindWindow("EVERYTHING",0),WM_COMMAND,MAKEWPARAM(41007,0),0);

The full path and filename of all the selected files will be copied to the clipboard.
Ralf_Reddings
Posts: 120
Joined: Fri Mar 24, 2023 4:53 pm

Re: how to get file path

Post by Ralf_Reddings »

Pardon me for not getting back to you sooner, I though I created a thread and that it was not approved by MODs. I was looking at the wrong place.

I think I may have confused myself then, as I thought the code I was using, shared by user Skier few posts up, was using the hidden result list focus window.
The text of the hidden result list focus window is always the full path and filename.
It doesn't matter what display_full_path_name setting you are using.
Well this is exactly what I am intrested in, how does one even invesitage this window?
For example I wanted to see get its text with AutoHotkey, Does it have a title or another Identifier that I could target it with?
SendMessage(FindWindow("EVERYTHING",0),WM_COMMAND,MAKEWPARAM(41007,0),0);
Is that AutoHotkey code? It looks like C++, I am afraid I only know how to use Autohotkey.

Thanks for your help.
void
Developer
Posts: 16671
Joined: Fri Oct 16, 2009 11:31 pm

Re: how to get file path

Post by void »

Please try the following:

SendMessage, 0x111, 41007,,, ahk_class EVERYTHING

0x111 is WM_COMMAND
41007 is the command to copy the full path and filename of the current result list selection to the clipboard.

How to Copy the Full Path to Clipboard via Autohotkey
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: how to get file path

Post by NotNull »

Ralf_Reddings wrote: Mon Mar 27, 2023 6:19 pm how does one even invesitage this window?
I think you mean Control instead of window?
I wrote an AHK script to investigate windows. There it came up.
See controls.ahk below (Win + Z to investigate the current active window)

See my code above to get the path without using the clipboard.
The core of it:

Code: Select all

ControlGetText, _FoundPath, EVERYTHING_RESULT_LIST_FOCUS1, A



controls.ahk

Code: Select all

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#singleinstance force


	_fileName :=  A_ScriptDir . "\export.csv"

	DetectHiddenWindows, On
	DetectHiddenText, On
	
#z::
{

	SetFormat, Integer, D

;	Header for list
	Gui, Add, ListView, r30 w1000, Control|ID|PID||Text|Visible|X|Y|Width|Height

;	Loop through all controls
	WinGet, ActivecontrolList, ControlList, A

	Loop, Parse, ActivecontrolList, `n
	{
	;	Get ID
		ControlGet, _ctrlHandle, Hwnd,, %A_LoopField%, A

	;	Get Text
		ControlGetText _ctrlText ,, ahk_id %_ctrlHandle%

	;	Get Visible
		ControlGet, _ctrlVis, Visible,,, ahk_id %_ctrlHandle%

	;	Get control coordinates
		ControlGetPos _ctrlX, _ctrlY, _ctrlWidth, _ctrlHeight, , ahk_id %_ctrlHandle%

	;	Get PID
		_parentHandle := DllCall("GetParent", "Ptr", _ctrlHandle)

	;	Add to listview ; abs() for hex to dec
		LV_Add(, A_LoopField, abs(_ctrlHandle), _parentHandle, _ctrlText, _ctrlVis, _ctrlX, _ctrlY, _ctrlWidth, _ctrlHeight  )

	;	Clean up for next control
		_ctrlHandle := ""
		_parentHandle := ""
		_ctrlText := ""
		_ctrlVis := ""
		_ctrlX := ""
		_ctrlY := ""
		_ctrlWidth := ""
		_ctrlHeight := ""

	}

	LV_ModifyCol()  ; Auto-size each column to fit its contents.
	LV_ModifyCol(2, "Integer")
	LV_ModifyCol(3, "Integer")
	LV_ModifyCol(5, "Integer")


	Gui, Add, Button, y+10 w100 h30 gDebugExport, Export 
	Gui, Add, Button, x+10 w100 h30 , Cancel 
	Gui, Show

}
Return




DebugExport:

	
	oFile := FileOpen(_fileName, "w")   ; Creates a new file, overwriting any existing file.
	If (IsObject(oFile))
	{
	;	Header
		_line := "ControlName;ID;PID;Text;Visible;X;Y;Width;Height"

		oFile.WriteLine(_line)

		Gui, ListView
		Loop % LV_GetCount()
		{
			_line := A_Index
			Loop, 9
			{
	;			MsgBox %A_Index%
				LV_GetText(_col%A_Index%, _line, A_Index)
	;			MsgBox % "col = "  _col%A_Index%
				_outline := _outline . _col%A_Index% . ";"
	;			MsgBox _outline = %_outline%
			}

			oFile.WriteLine(_outline)
			_outline := ""
		}

		oFile.Close()
		oFile:=""

		Msgbox File %_filename% exported

	}
	else
	{
		Msgbox Can't write to %_fileName% !
	}
	gosub ButtonCancel
Return

ButtonCancel:

		LV_Delete()
		GUI, Destroy

Return

Ralf_Reddings
Posts: 120
Joined: Fri Mar 24, 2023 4:53 pm

Re: how to get file path

Post by Ralf_Reddings »

void wrote: Thu Apr 06, 2023 3:52 am Please try the following:

SendMessage, 0x111, 41007,,, ahk_class EVERYTHING

0x111 is WM_COMMAND
41007 is the command to copy the full path and filename of the current result list selection to the clipboard.

How to Copy the Full Path to Clipboard via Autohotkey
Excellent, I will give this ago ASAP. Thanks!

@NotNull, I will also take a look at your code.

Thanks for helping me.
Post Reply