Context of "Search in contents" results?

Features wanted...
Post Reply
bbfyy
Posts: 3
Joined: 19 Oct 2016 00:12

Context of "Search in contents" results?

Post by bbfyy »

Maybe I missed this, but I'd like to:

- Find Files > Contents > plain text string

and have it show the actual line where the string was found -- is that possible? (not the line number, the full line)


So if I search for "dog", the results would show something like

animals.txt "The red dog jumped over the blue cat"

highend
Posts: 14658
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Context of "Search in contents" results?

Post by highend »

Welcome to the forum.

No, this is not possible atm.
One of my scripts helped you out? Please donate via Paypal

ds1508
Posts: 17
Joined: 19 Jul 2016 12:51
Location: NRW, Germany

Re: Context of "Search in contents" results?

Post by ds1508 »

You could do this with a script. But this would not be very effective or fast.
For what do you need this? Search in selected files only, complete directories, witch file types?
Writing a script then should not be that hard.

What do you want to do with the result?
A simple list, selectable, results to a log file?
In special cases you may contact me on Discord: http://bit.ly/dsDisco

highend
Posts: 14658
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Context of "Search in contents" results?

Post by highend »

A "scripted" way (you need to execute this after your search is complete and ofc you need the pro version of XYplorer) could look like this:

Code: Select all

    $results = "";
    foreach($file, <get itemspathnames |>) {
        $query = get("find_contents");
        $content = regexreplace(readfile($file), "\r?\n", <crlf>) . <crlf>;
        $matches = regexmatches($content, "^.*" . $query . ".*?(?=$)", <crlf>);
        $results = $results . quote($file) . ":<crlf>" . $matches . <crlf 2>;
    }
    text "Results:<crlf>========<crlf 2>" . $results;
Be careful it's only written for literal searches, wildcards are not translated into regex expressions...
One of my scripts helped you out? Please donate via Paypal

bbfyy
Posts: 3
Joined: 19 Oct 2016 00:12

Re: Context of "Search in contents" results?

Post by bbfyy »

Thanks for the replies.

I use this for finding the correct file when there are lots of results.

So I search for a text string but get a ton of results and if the results show the context then it's much easier to visually scan the results to find the correct file.


Can I assign a button to an external tool that accepts the current folder as a command-line option? I was thinking of using Grepwin ( https://sourceforge.net/projects/grepwin/?source=navbar ) since it does show context for results.

highend
Posts: 14658
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Context of "Search in contents" results?

Post by highend »

Sure you can.

Add a user button to the toolbar like this one:
button.png
button.png (8.42 KiB) Viewed 1664 times
This is the code for the left click:

Code: Select all

run """D:\Tools\grepWin\grepWin.exe"" /searchpath:""<curpath>""", <xypath>, 0, 0;
You have to change the path to grepwin (for the icon + the script line) and add additional parameters if you need them...
One of my scripts helped you out? Please donate via Paypal

bbfyy
Posts: 3
Joined: 19 Oct 2016 00:12

Re: Context of "Search in contents" results?

Post by bbfyy »

Awesome, thanks!

Post Reply