renameFilesWithSubstring function

void renameFilesWithSubstring(
  1. String path,
  2. String substring,
  3. String newName
)

Implementation

void renameFilesWithSubstring(String path, String substring, String newName) {
  Directory(path).listSync(recursive: true).forEach((entity) {
    if (entity is File) {
      String fileName =
          entity.path.split(Platform.pathSeparator).last.toLowerCase();
      if (fileName.contains(substring.toLowerCase())) {
        String newPath = entity.path
            .replaceAll(substring.toLowerCase(), newName.toLowerCase());
        entity.renameSync(newPath);
      }
    }
  });
}