Archive for January 20th, 2008

Search text in files

Story began when I was customizing some wordpress templates on my vista powered PC. I was curious what kind of PHP source code is behind the “the_content” tag, so that I tried to type word “the_content” in the windows explorer’s search box. This search did not appear to work. No file found.

This triggered a long journey digging into how to search the text in php files.

Method 1: Use Visual Studio, Edit | Find in files … (27 files found)

Method 2: Use FINDSTR in command prompt.
>findstr /si the_content *.php

Method 3: Use PowerShell
> dir . *.php -r | select-string the_content  | group-object Path | select-object Name, @{Expression={$_.Group | foreach {$_.LineNumber} }; Name=”Line Numbers”}, Count | format-list (c.f. this post)

Had so much fun learning PowerShell. :)  Spent a lot time on this. 

However, why Vista cannot search? The answer is the php files’ index options was “Indexing Properies”, but should be ”Indexing Properties and File Contents” in Control Panel - Classic View - Indexing Options - Advanced - File Types.

Finally also learnt that Vista search is word based, not character based. And maybe Vista search tokenized “the_content” same as “the content”, because the files have “the content” showed up, when searching “the_content”.

What a weekend, just like the comedy channel said, Time Well Wasted :)

Add comment January 20th, 2008


Calendar

January 2008
M T W T F S S
« Dec   Feb »
 123456
78910111213
14151617181920
21222324252627
28293031  

Posts by Month

Posts by Category


1