Hey,

I just created a small script that can help us sysadmins find data files on servers (and home systems).
I thought it would be handy to post it here so it can be of use for other server managers (as well as to have a repository where I can find it in the future).

Level: Intermediate

Background for writing this:
I manage servers that process 1000's of files each day. The contents of these files are in effect text-based records, used to produce prints in our printing layout system, as well as they comprise electronic (EDI) messages for orders, invoices. dispatch advices, shipment notices etc.
I found it nearly impossible to configure Windows 2008 to search through these files' contents (if I am, for instance, searching for a particular invoice number inside the print files).
The file's extensions vary wildly, for instance .txt and .xml, but also more exotic ones like .ps for Postscript, .ans for ANSI X.12, .edi for EDIFACT or .dat for anything.
Indexing these files is no option, as they are processed immediately and archived every day.
For ASCII-based files I created below batch file which can assist you to list the files containing a particular string (Caveat: UNICODE strings are a problem!).
The script should run fine on Windows 7 and 2008 (tested), as well as Windows XP and up (untested, but syntax on these systems is the same).

Batchfile find_in_files.bat:
Code:
@echo off
set FLR=%~1
if not defined FLR set /p FLR=Enter path to search IN: 
if not defined FLR goto :CANCEL
@echo Searching IN: %FLR%\*.*
set TXT=%~2
if not defined TXT set /p TXT=Enter text to search FOR: 
if not defined TXT goto :CANCEL


@echo Searching for "%TXT%"
@for %%I in ("%FLR%\*.*") do @(@find /c /i "%TXT%" "%%~I" >NUL && @echo Found: %%~nxI)
@goto :EXIT

:CANCEL
@echo Cancelled!


:EXIT
pause
And, for ease of use, also a .reg file to add it to the context menu on a server.
This assumes the batchfile is stored in c:\addpgms (a folder I normally include in the system's PATH of any server), but of course should be changed to whichever location you choose to use (be wary of spaces in this path!)

Code:
Windows Registry Editor Version 5.00


[HKEY_CLASSES_ROOT\Folder\shell\FindInFiles\command]
@="cmd.exe /c c:\\addpgms\\find_in_files.bat \"%L\""
Hope this is of any use to anybody,

Regards Eelco