mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
6ecc3c9076
* test: add document sync test on appflowy cloud * chore: add runner * test: Stream has already been listened to. * fix: using singleton subscription * fix: using singleton subscription
31 lines
840 B
Dart
31 lines
840 B
Dart
import 'dart:io';
|
|
import 'package:path/path.dart' as p;
|
|
|
|
Future<void> deleteDirectoriesWithSameBaseNameAsPrefix(
|
|
String path,
|
|
) async {
|
|
final dir = Directory(path);
|
|
final prefix = p.basename(dir.path);
|
|
final parentDir = dir.parent;
|
|
|
|
// Check if the directory exists
|
|
if (!await parentDir.exists()) {
|
|
// ignore: avoid_print
|
|
print('Directory does not exist');
|
|
return;
|
|
}
|
|
|
|
// List all entities in the directory
|
|
await for (final entity in parentDir.list()) {
|
|
// Check if the entity is a directory and starts with the specified prefix
|
|
if (entity is Directory && p.basename(entity.path).startsWith(prefix)) {
|
|
try {
|
|
await entity.delete(recursive: true);
|
|
} catch (e) {
|
|
// ignore: avoid_print
|
|
print('Failed to delete directory: ${entity.path}, Error: $e');
|
|
}
|
|
}
|
|
}
|
|
}
|