Renaming Sidecar (xmp photo metadata) Files

I’m working on a script to rename image files in Microsoft’s Expression Media 2. My catalog doesn’t include the sidecar (*.xmp) files that Photoshop generates, but I would like to rename them along with the raw files. I found a renaming script in Microsoft’s samples that handles files selected in EM2, but I’m struggling with figuring out how to rename a file that wasn’t part of the selection. In pseudo code, what I’d like to do it:

for each oldname
   generate a newname
   rename image file as newname
   if the file ((oldname - extension) & ".xmp") exists
      rename sidecar as ((newname - extension) & ".xmp")
   end if
end for

Can anybody point me to an example of how to do something like this?

Thanks, Doug

Browser: Safari 526.11.2
Operating System: Mac OS X (10.5)