backupFiles method
Backs up existing files before overwriting them.
Creates backup copies of files that will be overwritten during generation, allowing for recovery if needed.
Parameters:
filePaths: List of file paths to backupbackupSuffix: Suffix to append to backup files (default: '.backup')
Returns a map of original paths to backup paths.
Implementation
Map<String, String> backupFiles(
List<String> filePaths, {
String backupSuffix = '.backup',
}) {
final backupMap = <String, String>{};
for (final filePath in filePaths) {
if (exists(filePath)) {
final backupPath = '$filePath$backupSuffix';
try {
copy(filePath, backupPath);
backupMap[filePath] = backupPath;
} catch (e) {
print('Warning: Failed to backup $filePath: $e');
}
}
}
return backupMap;
}