Script to use Everything search from FC

Discussion, questions and support.
Post Reply
Message
Author
horst.epp
Posts: 236
Joined: 15.11.2008, 20:18

Script to use Everything search from FC

#1 Post by horst.epp » 18.10.2021, 18:39

This Autohotkey script allows to feed the search results from an Everything GUI window
into an Free Commander File container and automatically display it with FC.

Minimum FC version is FreeCommander XE 2021 Build 854 64-bit.

If you don't have it already running, download and install Everything from
https://www.voidtools.com/forum/viewtop ... =12&t=9787

Download my Autohotkey script and store it for example in a sub-dir Scripts of the FC settings dir
Customize the indicated parts of it.
Compile it with Autohotkey (Context menu 'Compile Script')
Add it as favorite in FC and assign a hotkey to it or pin it to the taskbar.

Usage:
Start Everything GUI and search your files.
Hit the hotkey or start the compiled script from the pinned taskbar entry.
The script stores the dsiplayed Everything GUI results in a file container and starts FC with it.
The script also stores an ini file in its dir which you can use to change parameters
without a need to recompile it.

Have fun.
Warning, you will never use any File managers search after using Everything :)

Code: Select all

; Transfer Everything GUI results to FC
; Author: Horst.Epp
; Last modified: 21.10.2021
 
; Build AutoHotkey_L
; Build x64
; Build Kill=true
; Build Zip=false
; Build Run=true

#NoEnv
;#Persistent
#SingleInstance Force
SetBatchLines, -1

; Create / read .ini file settings
SetTitleMatchMode, RegEx
iniFile := RegExReplace(A_ScriptFullPath, "(ahk|exe)$", "ini")

if not (FileExist(iniFile)) {
    iniContent :="
    (( LTrim
        [General]
	; DestinationFile
        ;    Where to save the output (full path to DestinationFile.fcc)
        ; EverythingColumnPositions (Default: 2,1)
	;    The columns 'Name' and 'Path' must be visible in the Everything GUI Window
        ;    The first value is the position of the 'Path' column
        ;    The second value is the position of the 'Name' column
	; CloseEverything (Default 1 for yes)
	;    Should Everything GUI window be closed after transfering to FC
	; UseInstance (Empty for default instance)
        ;    Name of the Everything instance to be used for closing the GUI
	; FreeCommander
	;    Full path to the FC executable file
	; Everything
	;    Full path to the Everything executable file 

; The contents of the following lines must be adjusted if necessary, e.g. path and parameter adjustments.
;********************************************************************************************************
        DestinationFile = C:\Tools\FreeCommander\Settings\FileContainers\Everything.fcc
        EverythingColumnPositions=2,1
        AddEndSlash = 0
        CloseEverything = 1
        UseInstance =
        Everything = C:\Tools\Everything\Everything64.exe
        FreeCommander = C:\Tools\FreeCommander\FreeCommander.exe
;********************************************************************************************************

    )"
    FileAppend, % iniContent, % iniFile, UTF-16
}
IniRead, DestinationFile, % iniFile, General, DestinationFile, %A_Space%
IniRead, EverythingColumnPositions, % iniFile, General, EverythingColumnPositions, 2`,1

IniRead, AddEndSlash, % iniFile, General, AddEndSlash, 0
IniWrite, %AddEndSlash%, % iniFile, General, AddEndSlash
IniRead, CloseEverything, % iniFile, General, CloseEverything, 1
IniWrite, %CloseEverything%, % iniFile, General, CloseEverything
IniRead, UseInstance, % iniFile, General, UseInstance, %A_Space%
IniWrite, %UseInstance%, % iniFile, General, UseInstance

IniRead, Everything, % iniFile, General, Everything, "C:\Tools\Everything\Everything64.exe"
IniRead, FreeCommander, % iniFile, General, FreeCommander, "C:\Tools\FreeCommander\FreeCommander.exe"

DestinationFile           := ResolveEnvVars(DestinationFile)
EverythingColumnPositions := StrReplace(EverythingColumnPositions, " ")

; Force error if none is given (or path doesn't exist)
SplitPath, DestinationFile, , dstPath
if (DestinationFile = "" || !InStr(FileExist(dstPath), "D")) {
    Msgbox, 16, Fatal error, Destination file definition is missing or illegal named !
    Return
}
if (EverythingColumnPositions = "" || !InStr(EverythingColumnPositions, ",")) {
    EverythingColumnPositions := "2,1"
}

columnArray := StrSplit(EverythingColumnPositions, ",")

hWnd := WinExist("ahk_exe Everything(?:\d\d)*\.exe")

if hWnd
{
  ControlGet, winContent, List, , SysListView321, % "ahk_id" hWnd

  if (winContent)
  {
    fullContent := "#FreeCommander file cart" "`n"
;   Loop over row(s)
    Loop, Parse, winContent, `n
    {
      rowID := A_Index
      path  := ""
      name  := ""
      full  := ""
      Bad := 2
;     Loop over column(s)
      Loop, Parse, A_LoopField, % A_Tab
      {
        colID   := A_Index
        content := A_LoopField
        If (colID > columnArray[1] And colID > columnArray[2])
        {
          Break
        }
        Else
        {
          If (colID = columnArray[1])
          {
	    If !RegExMatch(content,"i)^[a-z]:|\\\.*?\\")
            {
              Break
            }
            path := content
            Bad -= 1
            If !RegExMatch(path,"\\$")
            {
              path := path . "\"
            }
          }
          Else if (colID = columnArray[2])
          {
            If content is Space
            {
              Break
            }
            name := content
            Bad -= 1
          }
        }
      }
      If (Bad == 0)
      {
        full        := path . name
        If InStr(FileExist(full), "D")
        {
          if (AddEndSlash == 1)
          {
            if !RegExMatch(full,"\\$")
            {
              full := full . "\"
            }
          }
          Else
          {
            If RegExMatch(full,"\\$")
            {
              full := SubStr(full,1,StrLen(full)-1)
            }
          }
        }
        fullContent .= full "`n"
      }
    }
    fullContent := RegExReplace(fullContent,"\R$","")

    If (FileExist(DestinationFile))
      FileDelete, % DestinationFile

	FileAppend, % fullContent, % DestinationFile, UTF-8
	DestinationDir := SubStr(DestinationFile,1,InStr(DestinationFile, "\",,-1))
   	run %FreeCommander% /C %DestinationFile%
	If (CloseEverything) {
             run %Everything% -instance "%UseInstance%" -close
	}
    }
    Else
;   Empty search result
    {
      Msgbox, 16,, Search result is Empty, Nothing to do ...
    }
; No Everything window visible
} Else {
    Msgbox, 16, Fatal error, Everything window does not exist!
}
SetTitleMatchMode, 1
return

; ==================================
; = GOTO: FUNCTIONS - ResolveEnvVars
; ==================================
; http://www.autohotkey.com/board/topic/40115-func-envvars-replace-environment-variables-in-text/#entry310601
ResolveEnvVars(str) {
    if sz := DllCall("ExpandEnvironmentStrings", "uint", &str, "uint", 0, "uint", 0)
    {
        VarSetCapacity(dst, A_IsUnicode ? sz * 2 : sz)
        if DllCall("ExpandEnvironmentStrings", "uint", &str, "str", dst, "uint", sz)
            return dst
    }
    return str
}

Last edited by horst.epp on 27.11.2021, 18:08, edited 2 times in total.
Windows 11 Home x64 Version 21H2 (OS Build 22000.318)
Everything Version 1.5.0.1285a (x64)
FreeCommander XE 2021 Build 859 64-bit donor

Odamn-Ete
Posts: 267
Joined: 28.06.2017, 07:10

Re: Script to use Everything search from FC

#2 Post by Odamn-Ete » 22.10.2021, 15:08

Thanks horst.epp for sharing this. It is very interesting.

Your link brought me to the Forum section for Everything 1.5.0 Alpha. The stable version of Everything search is 1.4.1.

For which version is your script applicable?

Is there any way to create such a script without Autohotkey?
Installing it just to compile/run a single script is something I'd prefer not do.
There's not much, if anything, I need to automate per script, if you understand what I mean.

Best regards,

horst.epp
Posts: 236
Joined: 15.11.2008, 20:18

Re: Script to use Everything search from FC

#3 Post by horst.epp » 22.10.2021, 15:38

Hello,
I use and test with Everything version 1.5 alpha
but my script should run without any modification also for Everything 1.4.
I suggest using version 1.5.
It runs very stable and has features like content indexing and is so much better than version 1.4.

The way the script works may be ported to other languages but why ?
The Autohotkey installer is only about 3 MB and has no dependencies.

Best regards
Horst Epp
Windows 11 Home x64 Version 21H2 (OS Build 22000.318)
Everything Version 1.5.0.1285a (x64)
FreeCommander XE 2021 Build 859 64-bit donor

Forez
Posts: 583
Joined: 30.01.2016, 12:05
Location: In front of a PC monitor

Re: Script to use Everything search from FC

#4 Post by Forez » 09.11.2021, 21:49

This Everything seems to be interesting helpful tool

I will test it, as even with my [theoretically] super fast M.2 NVMe drive I often have to stare at FreeCommander search window spitting the results one by one

Post Reply

Who is online

Users browsing this forum: GeezZzer and 13 guests