renameFilesWithSubstring function
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);
}
}
});
}