collectFolderInfo function
Implementation
List<Tuple2<String, String>> collectFolderInfo(String directoryPath) {
Directory directory = Directory(directoryPath);
List<Tuple2<String, String>> folderInfo = [];
if (!directory.existsSync()) {
print("Directory does not exist");
return folderInfo;
}
List<FileSystemEntity> entities = directory.listSync(recursive: true);
Map<String, String> folderMap = {};
// Check each folder for 'usage.dart' or '_/_.dart' with 'class NewView'
for (var entity in entities) {
if (entity is File) {
String fileName = entity.path.split('/').last;
String folderName = entity.parent.path.split('/').last;
String relativePath = entity.path.replaceFirst('$directoryPath/', '');
String topFolderName = relativePath.split('/').first;
if (!topFolderName.startsWith('_new')) {
if (fileName == 'usage.dart') {
folderMap[topFolderName] = 'usage';
} else if (fileName == '_.dart') {
String content = entity.readAsStringSync();
if (content.contains('class NewView') && folderMap[topFolderName] != 'usage') {
folderMap[topFolderName] = 'newview';
}
}
}
}
}
folderMap.forEach((key, value) {
folderInfo.add(Tuple2(key, value));
});
return folderInfo;
}