I've now discovered the cause of this- Brackets in the filenames (Arrgh- root was a red herring caused by my test file)
I've added the suggested error checking and two more sets of rename statements to cope with these at present, which appears to be working.
Do you have an example of using Opendir for this sort of thing? I managed to get it to run MKVMerge for every file, but I can't get it to play nice with the extensions.
Cheers