HELP! Need search advice

I am trying to search a folder on an OS X server from an OS 9.2 machine but I am having problems getting the search to work. I want to open file text file, get the ad list it contains, search the server for the ads, and then upload them to a ftp site. I am having problems getting past the search part. My code is as follows:

set search_string to “408039” – ad number for testing
set fol_ to “PDF Server:Classifieds PDF Files:Out:”

tell application “Finder”
set files_ to (files of fol_ whose name begins with search_string) as alias list
end tell

repeat with file_ in files_
display dialog file_
end repeat

I get the following error when trying to run the script.

–Can’t make every file of “PDF Server:Classifieds PDF Files:Out:” whose name starts with “408039” into a «class alst».

Any thoughts on what I may be doing wrong?


Firstly, strings don’t have files. You need to turn the path string into a folder specification:

tell application "Finder"
  set files_ to (files of folder fol_ whose name begins with search_string) as alias list -- NB. 'folder'
end tell

If there’s only one file whose name begins with the search string, the above will error owing to a long-standing bug in Finder scripting. The usual way to deal with this is a ‘try’ block:

tell application "Finder"
  try
    set files_ to (files of folder fol_ whose name begins with search_string) as alias list
  on error
    set files_ to (first file of folder fol_ whose name begins with search_string) as alias as list
  end try
end tell

Secondly, when you get there, ‘display dialog’ doesn’t display aliases but strings, so:

repeat with file_ in files_
  display dialog (file_ as string)
end repeat

Thanks, it works great. I haven’t written many scripts so sometimmes the little things get missed. BTW, the display dialog line was just there as a place holder for what really will be there (when I get it worked out).