clearDirectory function

void clearDirectory(
  1. {@required Directory directory,
  2. bool isDeleteDirectory = false}
)

清理文件夹

Implementation

void clearDirectory({@required Directory directory, bool isDeleteDirectory = false}){
  if (directory.existsSync()) {
    List<FileSystemEntity> files = directory.listSync();

    if (files.length > 0) {
      files.forEach((file) {
        ///当包含文件夹的时候
        if (file.statSync().type == FileSystemEntityType.directory)
          clearDirectory(directory: Directory(file.path), isDeleteDirectory: true);
        else
          file.deleteSync();
      });
    }
    if (isDeleteDirectory)
      directory.deleteSync();
  }
}