if, then not working

I am having difficulty getting an if, then to work correctly. This part of my script looks for some pdf files that have been created and then moves them if they exist. If they do not exist then I want to put some text into a variable so that I can use it in a log that I create. Regardless of whether there are files or not, the script always tries to move the selections rather than getting trapped by the “if selection = {}” .I am running Mac OS 9.2.1. What might I be doing wrong? Thanks. . . .
select (the files in folder pdfsourceFolder whose name contains PubDate and name contains “PDF”)
try
if selection = {} then
set No_Files to "There are no pdf files created for date " & PubDate
else
move selection to pdfFinalFolder replacing yes
end if
end try

: I am having difficulty getting an if, then to work correctly. This part of my
: script looks for some pdf files that have been created and then moves them
: if they exist. If they do not exist then I want to put some text into a
: variable so that I can use it in a log that I create. Regardless of
: whether there are files or not, the script always tries to move the
: selections rather than getting trapped by the “if selection =
: {}” .I am running Mac OS 9.2.1. What might I be doing wrong? Thanks.
: . . .
: select (the files in folder pdfsourceFolder whose name contains PubDate and
: name contains “PDF”)
: try
: if selection = {} then
: set No_Files to "There are no pdf files created for date " &
: PubDate
: else
: move selection to pdfFinalFolder replacing yes
: end if
: end try

Try this:

– Begin Script –

select (the files in folder pdfsourceFolder whose name contains PubDate and name contains “PDF”)
try
if (count of selection) = 0 then
set No_Files to "There are no pdf files created for date " & PubDate
else
move selection to pdfFinalFolder replacing yes
end if
end try

– End Script –

Rob, Thanks for getting back to me. I did try what you suggested but regardless of the number of files present, I always get a return of 0 for the number of files. Here is what I got from the Event Log:—thanks again
select every file of folder (alias “pdf_pages_out:out:”) whose name contains “Mar_22_02” and name contains “PDF”
→ {file “Mar_22_02_A03.PDF” of folder “out” of disk “pdf_pages_out”, file “Mar_22_02_A04.PDF” of folder “out” of disk “pdf_pages_out”, file “Mar_22_02_A01.PDF” of folder “out” of disk “pdf_pages_out”, file “Mar_22_02_A02.PDF” of folder “out” of disk “pdf_pages_out”}
count every selection of current application
→ 0