Search drive in AppleScript?

Hi all,

I did a quick search of the forum, but didn’t really find a related topic (maybe I missed it.)

I’m trying to write an Applescript that can find certain files (given an input) ANYWHERE on a selected hard drive. I already have the input part and I can get it to match one folder level deep – but it that’s it. I need it to search every file in every folder on the whole hard drive…

I have an idea of how I MIGHT do this using a conditional loop with different “levels,” analyzing the number of folders in each folder and proceeding until it hits zero and then going back through each level – but I would rather not have to write a complicated search function from scratch. If anyone could point me in the right direction or give me some tips, that would be great.

Thanks!

try this, but be prepared to wait a long time

do shell script "find '/Volumes/name of drive/'"

If you want to search by file name, try something like this:

list disks
choose from list (result) with title "Choose disk:" with prompt "" default items {item 1 of result}

set theDisk to POSIX path of ((first item of result) as alias)
if (length of result) is not 1 then set theDisk to (characters 1 through -2 of result) as string

display dialog "Search for this name:" default answer ""

do shell script "find " & quoted form of theDisk & " -iname " & (text returned of result)

You may have permission problems with certain folders, such as “.Trashes”.

In OS 9 (as this is the Mac OS forum) you have:

http://osaxen.com/files/finddocument2.7.html

I can post a vanilla-AS search script, but it could take loads of time (eg, 20 minutes) in a large volume.

BTW, some times you are looking for a file which is in fact in a known (or guess-able) place (eg, prefs dir, apps dir, any dir related to a specific app, etc.). Otherwise (eg, a random name in the hard disk), the better way is allways prompting the user for the location of such “random named” file.

Thanks everyone! I’ll give some of these a try.

I would just prompt the user for a location if that was going to be known, except that the script ultimately has to read a file of hundreds of file names, search for those files and then move them. But if its going to take a long time per search, then I might be out of luck.