opening folders within a certain criteria

This has me stumped: How do I find every folder within a criteria. For example, how would I write a script that finds every folder in my home directory that contains a text file?.

Interesting question. I can’t think of anything other than a repeat right now:

set a to path to home folder
tell application "Finder"
	set b to every folder of entire contents of a
	set the_List to {}
	repeat with c in my b
		if (get name extension of every file of c) contains "txt" then
			set end of the_List to {c's name, (c's container as Unicode text)}
		end if
	end repeat
end tell

I am confident there is a more elegant way to do this. It is too late for me, however.

i’m a big fan of shell scripting but this does it recursivly

do shell script "find ~ -name *txt "