> On Dec 07, 2021, at 20:44, Richard Fairbanks <[email protected]> wrote:
> I want BBEdit to return the number of times a text string appears in the 
> files in a directory. The following works to replace any such text:


Hey Richard,

The simple way is to do a straight file search:



If you want to script it then you need to do something like this:

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/12/07 22:17
# dMod: 2021/12/07 22:17 
# Appl: BBEdit
# Task: Count the Number of Files Containing a Search String – 
Recursive-File-Search
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @BBEdit, @Count, @Files, @Containing, 
@Search, @String, @Recursive, @Search
--------------------------------------------------------
use AppleScript version "2.4" --» Yosemite or later
use framework "Foundation"
use scripting additions
--------------------------------------------------------

set searchDir to "~/test_directory/Many_Files_6000/"

set searchDir to ((current application's NSString's 
stringWithString:searchDir)'s ¬
    stringByExpandingTildeInPath) as text

tell application "BBEdit"
    set foundRecord to find "three\\nfour" searching in searchDir options 
{search mode:grep, case sensitive:false, starting at top:true, returning 
results:true}
    
    if found of foundRecord then
        return length of found matches of foundRecord
    end if
    
end tell

--------------------------------------------------------


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "[email protected]" rather than 
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/650B3CC0-CC8A-49BE-BB65-999B9D3FC04A%40gmail.com.

Reply via email to