Cheers for this tips Phil - I'm not sure the optimisations really matter for a handful of files on a modern CPU, but you are right - there are neater ways to do this. The escaping is a more important point though - I think I'll spend some time today doing a more polished version of the script.

Bart.