I would like to find a particular string in a set of nb files in a directory but am having problems interpreting the results of my code. Here's a simple example:
In directory d:\mathematica, I have the following 6 nb files:
theFileNames = {"benchmarks.nb", "ILE stylesheet.nb",
"iteration121420.nb", "iteration121720.nb", "testExample.nb",
"vectorIterationPlot.nb"}
In testExample.nb, I inserted the string "this is my string". Next I would like to search all the nb files in d:\mathematica and locate any that have this string:
searchData = Table[
theName = "d:\\mathematica\\" <> theFileNames[[i]];
nb = NotebookOpen[theName, Visible -> False];
result = NotebookFind[nb, "this is my string"];
NotebookClose[nb];
{i, result},
{i, 1, Length@theFileNames}
];
searchData
Which returns:
{{1, $Failed}, {2, $Failed}, {3, $Failed}, {4, $Failed}, {5,
NotebookSelection[
NotebookObject[FrontEndObject[LinkObject["g5uyb_shm", 3, 1]],
122]]}, {6, $Failed}}
Showing the fifth file returned a match. I would like to identify this file name but I can't simply code:
Position[searchData,{x_,y_}/;y!="$Failed"]
or:
Position[searchData,{x_,y_}/;y!=$Failed]
as neither of these seem to work. However this:
Position[searchData, {x_, y_} /; y == $Failed]
appears to find all the failed ones but is a bit messy and requires further processing. Can someone explain how to better identify the matching file names or suggest a more efficient way of searching a directory of nb files for a particular string?
TextSearch["C:/xyz/Mathematica" , "ImageCollage"]
and it returned aSearchResultObject
with the files in the directory containing this string. $\endgroup$