Author Topic: Exclude "binary" files from search results  (Read 664 times)

rowbearto

  • Senior Community Member
  • Posts: 935
  • Hero Points: 43
Exclude "binary" files from search results
« on: December 13, 2017, 09:51:51 pm »
Would be nice to have an option to exclude binary files from search results.

Graeme

  • Senior Community Member
  • Posts: 2061
  • Hero Points: 248
Re: Exclude "binary" files from search results
« Reply #1 on: December 14, 2017, 10:13:59 am »
Would be nice to have an option to exclude binary files from search results.
Why can't you exclude them from the search?  What kind of search are you doing?


rowbearto

  • Senior Community Member
  • Posts: 935
  • Hero Points: 43
Re: Exclude "binary" files from search results
« Reply #2 on: December 14, 2017, 02:19:56 pm »
See attached screenshot for my search and the search results.

I am using BigFind, List all occurences. You can see in the search window that I have binary files in the results. There are so many of these binary files it drowns out the shell scripts that I am really looking for. These shell scripts have no extension (no .sh), and the binary files also have no extension. So it would be difficult to figure out all the file patterns for excluding these binary files.

Instead, if a checkbox could be added to the BigFind window like "exclude binary files", then any file that the search finds has non-printable characters could be excluded from the search results.

Graeme

  • Senior Community Member
  • Posts: 2061
  • Hero Points: 248
Re: Exclude "binary" files from search results
« Reply #3 on: December 15, 2017, 05:58:28 am »
I'm a bit confused.  The screenshot shows "lookin" set to "current buffer"  - but the problem you describe is with searching multiple files.  If you're doing "find in files" there's a file types edit box that lets you specify the file types to search and an exclude edit box for exclusions.  So you can exclude all git or cvs folders etc.  The file types edit box lets you create your own filter and lets you order the filters so the ones you use most can be at the top.

rowbearto

  • Senior Community Member
  • Posts: 935
  • Hero Points: 43
Re: Exclude "binary" files from search results
« Reply #4 on: December 15, 2017, 02:02:06 pm »
I took the screenshot after the fact. I should have had it on the "Find in Files" tab, that is what the search was really done with. Here is a corrected screenshot.

Yes it is possible to use the "Exclude:" box - but this requires me to figure out ahead of time all of the directories and file patterns that I would want to exclude. I don't always know this ahead of time and it could be a tedious and time consuming process to figure this out when I just want to quickly proceed with my work.

But I do know ahead of time to exclude all files with non-printable characters. Therefore my request is to provide an option in BigFind to exclude any files that contain non-printable characters. It would save me much time to have this feature, time that I would be wasting trying to figure out all the filespecs to place into the "Exclude:" box.


Graeme

  • Senior Community Member
  • Posts: 2061
  • Hero Points: 248
Re: Exclude "binary" files from search results
« Reply #5 on: December 16, 2017, 04:47:40 am »
ok. Until slickteam get around to adding it you could try using the "filter search results" option in the context menu.  If you select slickedit regular expressions, a search string of '[\x80-\xff]|\x00' and choose the "delete line" option, you might be able to remove some of the binary file results.  If you add the code below to tbsearch.e then add the commands try_remove_binary and set_binary_filter to _grep_menu_default, they should show up in the context menu in the search results window.

Code: [Select]
#import "slickc.e"
// the above line has to be at the start of the file
_str def_binary_char_filter = '[\x80-\xff]|\x00';


_command void try_remove_binary() name_info(',')
{
   _search_filter(def_binary_char_filter, "IR", false, false);
}

_command void set_binary_filter() name_info(',')
{
   set_var('def_binary_char_filter');
}


[Edit] Undo and redo can be used after filtering in the search results window.
« Last Edit: December 16, 2017, 04:49:37 am by Graeme »

rowbearto

  • Senior Community Member
  • Posts: 935
  • Hero Points: 43
Re: Exclude "binary" files from search results
« Reply #6 on: December 16, 2017, 02:29:08 pm »
Thanks Graeme!

jporkkahtc

  • Senior Community Member
  • Posts: 1491
  • Hero Points: 123
  • Text
Re: Exclude "binary" files from search results
« Reply #7 on: January 29, 2018, 02:13:24 am »
I implemented this, but I've not posted it before because it requires modification of several built-in Slick macros.
Well, implemented it by filename extension.
The "Binary" language has many extensions assigned to it, and you can add more.

It would be better if Slick would recognize binary files by content, but I find this works pretty well.
In any case, it can at least reduce the amount of garbage you would then need to filter out of the results for the tough cases - where there isn't a simple filename pattern that would work.

It supports expansions of language *.ext, aliases, and env vars.
Load the macro file "joesAlias.e".
Make changes to tbfind.e as directed in alias_changes.e and reload tbfind.e


For example
   "#{Plain Text};"
expands to
   "*.asc;*.csv;*.err;*.log;*.tsv;*.txt;"
 
And
   "#Binary"
expands to
   "*.z;*.a;....long list of things...."

@alias
$envvar
@{alias}
${envvar}
\@
\$