cleanupTempFiles method

int cleanupTempFiles(
  1. List<String> tempFiles,
  2. List<String> backupFiles
)

Cleans up temporary and backup files.

Removes temporary files created during the generation process to keep the file system clean.

Parameters:

  • tempFiles: List of temporary file paths to remove
  • backupFiles: List of backup file paths to remove

Returns the number of files successfully cleaned up.

Implementation

int cleanupTempFiles(List<String> tempFiles, List<String> backupFiles) {
  var cleanedCount = 0;

  final allFilesToClean = [...tempFiles, ...backupFiles];

  for (final filePath in allFilesToClean) {
    try {
      if (exists(filePath)) {
        delete(filePath);
        cleanedCount++;
      }
    } catch (e) {
      print('Warning: Failed to cleanup $filePath: $e');
    }
  }

  return cleanedCount;
}