Very often I find myself need to search the contents of source files in development projects. This is more than just searching for files, typically I’m looking for a specific word or phrase contained anywhere within a file or many files. On linux platforms, grep makes this trivial. There are windows grep tools, but I’ve always felt the implementation is poor.
By default, Windows XP has a very basic file contents search, problem is it ignores many filetypes. Windows 7 may have improved on this, I’ll have to check into. There is a great utility however that is a vast improvement over the standard windows file contents search. See FileLocator , a powerful tool that performs file contents searching thats light years ahead of the windows built in search. The best parts of the filelocater tool are (1) it’s ability to run from the command line and (2) it’s ability to export results to a csv or text file. Good stuff.
Here’s an example cmd line run of this tool -
C:\Program Files\Mythicsoft\FileLocator Lite>FileLocatorLite.exe -o files-to-change.csv -ofc -ocn -d "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\local-devel" -c live.server.com -f *.php;*.js;*.html -s
In this cmd line we’re using filelocatelite.exe and using ‘-o’ switch to send output of the search to a csv file, files-to-change.csv.
The ‘-ofc’ switch specifies that we want csv output.
The ‘-ocn’ switch tells filelocator that we don’t want the actual content lines within the file that contain the string we’re searching for.
Next we specify the ‘-d’ switch to tell filelocator what directory we want to search in.
The ‘-c’ switch tells filelocator what string we’re looking for in the files, in this case ‘live.server.com’.
The ‘-f’ switch tells filelocator what files we want to include in the search, in this case we’ve specified them by file extension, *.php, *.js, and *.html.
Finally the ‘-s’ switch tells filelocator that we want to search all subdirectories. Voila!