listFilePaths function

Future<List<String>?> listFilePaths(
  1. String dirPath, {
  2. bool recursive = true,
})

Lists the file paths of the files in the directory located at dirPath. Set recursive to true to list the file paths of the files in the sub-directories as well.

Implementation

Future<List<String>?> listFilePaths(
  String dirPath, {
  bool recursive = true,
}) async {
  final localSystemDirPath = toLocalSystemPathFormat(dirPath);
  final dir = Directory(localSystemDirPath);
  final filePaths = <String>[];
  if (await dir.exists()) {
    final entities = dir.listSync(recursive: recursive);
    for (final entity in entities) {
      if (entity is File) {
        filePaths.add(entity.path);
      }
    }
  } else {
    return null;
  }
  return filePaths;
}