Results 1 to 1 of 1
2012-03-25, 10:04 #1
- Join Date
- Dec 2009
- Leiden, Netherlands
- Thanked 4 Times in 2 Posts
Searching any file for text on Windows 2008 (windows 7 too)
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).
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.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!).
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.
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).
@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
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!)
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Folder\shell\FindInFiles\command] @="cmd.exe /c c:\\addpgms\\find_in_files.bat \"%L\""
Regards Eelco- Eelco
*** Puzzle me! ***