FAST, PROGRAMMATIC string searching in directories of MATLAB code files

VERY FAST Command-Line searching for text contained in MATLAB code files.
Updated 1 Sep 2016

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Pre-analyze directories of MATLAB code to create searchable text files for very fast scanning for strings across multiple files.
The MathWorks 'Find Files' interface allows interactive searching for text in MATLAB files. |findInM| (in conjunction with its companion |collectCode|) allows you to search programmatically (i.e., from within a script or function, or at the Command Line), and can be much faster than any other method I've seen.
On first use, or when a New collection is requested, the user will be prompted to select a top-level directory and to indicate whether or not to recurse, and a new code collection will be created and stored. This will allow for very fast subsequent searches.
Comments/suggestions/collaborations welcome.

Cite As

Brett Shoelson (2024). FAST, PROGRAMMATIC string searching in directories of MATLAB code files (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on File Operations in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Updated license

(Once again, removed userpath).

Added special handling for 2-input case:
a = findInM(searchstring,collection); AND, added "Current-Directory" search:
a = findInM(searchstring,'pwd').

I made some general improvements, and allowed for sorting by date or size. Better auto-naming of code collections. Also added a screen shot.

Better naming convention