Extended process_dir to handle optional renaming