factor out inner loop of rcopy main into a file handling method