2012-03-25, 09: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! ***
Subscribe to our Windows Secrets Newsletter - It's Free!
Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!
+ Get this BONUS — free!
Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!