First off, please use code tags.

Take a look at line 3. ==>>$templates=enumdir($'directory')
You have a stray quote. This has been pointed out to you before. In fact you dont need any quotes on that line. Should be:
$templates=enumdir($directory)

Also, you are missing the dependent WshPipe() UDF. This too has already been pointed out to you.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.