We’re working on a script that selects specifically PDF files from a watched folder and moves them to another folder.
The problem is, if there isn’t a PDF file in the specified folder (and there often will not be), we recieve an error. In other words, the script is told to select all files containing “.pdf” and move them to the other folder.
IF there aren’t any, how can we make the exception and allow the script to move onto the next line?
The way to trap a possible error is to use a ‘try’ block:
try
-- do something that might cause an error
on error
-- take appropriate action or do nothing
end try
But I can’t understand why you’re getting an error in the first place. If you tell the Finder either to select or set a variable to ‘every file of folder myFolder whose name ends with “.pdf”’, then you’ll just get an empty list if none of the files meets the criterion.
Attempting to move that to another folder just does nothing. You would get an error if the line cntained something like ‘the name of every file of folder myFolder whose…’ etc., because then you’d be trying to access a property of non-existent items.
But the following should work without error whether there are qualifying files or not:
tell application "Finder"
move (every file of folder myFolder whose name ends with ".pdf") to folder anotherFolder
end tell