6
$\begingroup$

I have a lot of notebooks scattered in my downloads, documents and desktop folder. I have all the required locations on Windows indexing options but if I look at Advanced Options and File Types and nb extension. I can see it shows

Registered IFilter is not found

Windows search searches for file names and properties but is not searching within the notebooks. Where can I find the IFilters for Wolfram notebooks (version-12) for Windows 10?


Also even if there are no official IFilters, does anyone know how to get windows to use Plain Text Filter for nb file. Since even in plain format nb file opens revealing its box structure.

Since it is by default not encoded and function names don't get transformed in box language, I am happy to search the plain box language but how do I get windows to use Plain Text Filter without attempting any parsing. Since I remember the function names I used in the code that I am looking for in thousands of notebooks.


There is some guy on Wolfram Community saying that: "Spelunking on StackExchange suggests WDS capability was lost back around v10.2. It is a painful loss."

Can someone using version 10.2 or older check whether they are able to search within notebooks on Windows.

$\endgroup$

4 Answers 4

5
$\begingroup$

Here is a potential workaround.

Windows 10 has a feature called the Windows Subsystem for Linux. You should be able to activate from the start menu and typing "Windows Features" and selecting the first hit. Then, turn it on as shown in the image.

Windows Subsystem For Linux

Linux has a command called grep that provides many options to search text files. After installing, you can type bash into the start window and use the bash command shell to search files using grep. For example, the command grep -RH NotebookDirectory --include="*.nb" * will perform a recursive directory search for the term NotebookDirectory for all files matching the pattern *.nb.

Updated More Robust Answer

I have a Windows 7 and 10 system that both have the Linux emulator Cygwin installed. Since the Windows 10 machine has both Cygwin and the Subsystem for Linux, it can be confusing about which Linux system was called. It turns out that grep is stored in /bin/grep and /usr/bin/grep for the Subsystem for Linux and Cygwin, respectively.

I used the linux command which grep and RunProcess to confirm that my initial answer was picking up the Cygwin grep.

RunProcess[{"which", "grep"}, "StandardOutput"]
(* "/usr/bin/grep" *)

To access the Subsystem for Linux require that we prepend bash -c to the command or

RunProcess[{"bash", "-c", "which grep"}, "StandardOutput"]
(* "/bin/grep" *)

A more robust code that can handle either Cygwin or the Subsystem for Linux follows

SetDirectory[NotebookDirectory[]];
grepRecurse[searchterm_, filepattern_] := {"bash", "-c", 
  StringTemplate["grep -RH \"`1`\" --include=\"`2`\" *"][searchterm, 
   filepattern]}
cmd = grepRecurse["NotebookDirectory", "Int*.nb"];
s = RunProcess[cmd, "StandardOutput"];
Column@StringSplit[StringSplit[s, RegularExpression["\r?\n"]], ":"][[
  All, 1]]

Code with bash -c

Original Answer That Might Only Work with Cygwin in Path

Alternatively, you can issue the command from Mathematica directly using RunProcess workflow as shown below.

SetDirectory[NotebookDirectory[]];
grepRecurse[searchterm_, filepattern_] := {"grep", "-RH", 
   StringTemplate["\"`1`\""][searchterm], 
   StringTemplate["--include=\"`1`\""][filepattern], "*"};
cmd = grepRecurse["NotebookDirectory", "Int*.nb"];
s = RunProcess[cmd, "StandardOutput"];
Column@StringSplit[StringSplit[s, RegularExpression["\r?\n"]], 
   ":"][[All, 1]]

RunProcess Example

$\endgroup$
6
  • $\begingroup$ Are you on windows? is grep safe to use on windows file system? I have installed the subsystem for linux but still getting RunProcess::pnfd: Program grep not found. Check Environment["PATH"]. Do you need to add bash somewhere in your Mathematica code? $\endgroup$
    – user13892
    Commented Aug 24, 2019 at 16:48
  • $\begingroup$ I have both a Windows 7 and Windows 10 system. Unfortunately, I also have Cygwin installed on both, and that could be causing the discrepancy. If you run RunProcess[{"bash", "-c", "which grep"}, "StandardOutput"] does it return /bin/grep? If it does, then we should be able to adjust the function. $\endgroup$
    – Tim Laska
    Commented Aug 24, 2019 at 17:56
  • $\begingroup$ @user13892 I updated my post. By prepending the command with bash -c, it appears to be picking up the Subsystem for Linux. It has been a while since I installed, but I don't remember doing anything special. Let me know if you still have issues. $\endgroup$
    – Tim Laska
    Commented Aug 24, 2019 at 19:29
  • $\begingroup$ @user13892 Grep by itself should be safe on Windows. As far as I have ever used it, it is read-only. I have been using it a long time (15+ years) on windows because for me it was much faster than File Explorer especially when the directories had 1000s of files. I also checked that Windows installed the Subsystem bash.exe in C:\WINDOWS\system32. $\endgroup$
    – Tim Laska
    Commented Aug 24, 2019 at 21:21
  • $\begingroup$ Thank you your solution works and is very fast. I found the file I was looking for! Since you know how Linux command works, can you also guide me why commands I have added in bash to change the terminal size don't work through the RunProcess interface - see? $\endgroup$
    – user13892
    Commented Aug 28, 2019 at 11:01
4
$\begingroup$

Some time ago I've written a search routine which allows searching inside of Notebooks using string patterns:

Other solutions from that thread can also be of interest for you.


Alternatively you can program your own search routine on the base of one of the following functions:

  • Import[nbFilePath, "Plaintext"]

  • NotebookImport[nb, _ ->"InputText"]

  • First[FrontEndExecute[FrontEnd`ExportPacket[nb, "PlainText"]]]

You can find additional information on their usage in the following threads:

Note however that Import[nbFilePath, "Plaintext"] is based on "NBImport.exe" which has long-standing bug in importing files with non-ASCII filepaths.

$\endgroup$
1
$\begingroup$

No good news i'm afraid.

The same response is shown for Version 12.0. Assuming they didn't fix it just to break it, the intervening versions are probably bad as well.

If you have defined the functions in an initialization cell and auto-save the ".m" file, this file extension is set up to use plain text search. This is the method i use.

Otherwise, you might be able write a script to resave your files as ".m" and search those file as text.

Best of luck!

Mark

$\endgroup$
0
$\begingroup$

There is another answer from the Wolfram Community discussion linked in the OP's question:

Post

l van Veen (1 year ago)
It's very annoying but I found a fix with up to now no side effects. It seem that the .nb extension has no iFilter driver linked. I believe this could just be the standard .TXT. Windows 10 and MM12.o You can start regedt32 from the windows run prompt. Go to the Computer\HKEYLOCALMACHINE\SOFTWARE\Classes.txt\PersistentHandler Double click on the Default item and copy the GUID in my case as an example: {5e941d80-bf96-11cd-b579-08002b30bfeb} Go to the Computer\HKEYLOCALMACHINE\SOFTWARE\Classes.nb\PersistentHandler Double click on the Default item and Paste the GUID from the .txt (In my case there was no GUID entry in the Default entry which I guess triggers the "not registered message"..?) That's it and it worked for me. Would love to hear official Support statement from Wolfram though.. I also noted that for the .m and .ma files the same entries are used and these already worked as already explained by the OP.

Note: In this same discussion it's also mentioned how this will be probably less efficient because it searches through images, compressed data, etc., but that a standard .txt filter seems to be all that was ever used in the past (i.e. no custom iFilter from Wolfram).

How it worked for me

Turns out my .nb class had a GUID, but after following the above directions, it seems to work as expected.

My GUIDs

.txt
{5e941d80-bf96-11cd-b579-08002b30bfeb} (same as in post)
.nb
{FD28517F-25FF-4668-88C3-F95935B29F4A} (post said theirs was empty)

Comments

At first, it didn't seem to change the behavior. Thinking maybe I should rebuild the index, I started doing that. But soon after starting the rebuild, it started working as you'd expect in my Downloads folder. So maybe be a little more patient than me. (100,000 items indexed.. 105,000 items indexed.. 110,000 ..)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.