BatchIo: close the preview before writing or deleting result files (fixes #286 and #287)