AppleScript variant of find(1)

applescript

How would I write the following as an AppleScript command without the use of bash scripting?

find / -file foo.txt

I might have the bash syntax wrong, but I want to search from the root of the drive for a specific filename.

I tried drawing multiple efforts from things around on the net, but I just need a simple "find" solution.

Best Answer

Finder has an entire contents command for listing all items in a directory tree:

tell application "Finder"
    files of entire contents of (POSIX file "/usr/share/doc" as alias) where name is "bashref.html"
end tell

It will be really slow if you search in the root of the volume though. If you need to search for all files on the volume, you can use mdfind or locate:

do shell script "mdfind -name bashref.html -onlyin /"
do shell script "locate bashref.html"