cleanDirectory method

Future<void> cleanDirectory(
  1. String directory
)

Cleans a directory by removing all its contents.

Parameters:

  • directory: The path of the directory to clean

Removes all files and subdirectories in the specified directory. Creates the directory if it doesn't exist.

Implementation

Future<void> cleanDirectory(String directory) async {
  final dir = Directory(directory);
  if (await dir.exists()) {
    await for (var entity in dir.list()) {
      await entity.delete(recursive: true);
    }
  }
}