renameFilesWithSubstring static method
Implementation
static Future<void> renameFilesWithSubstring({
required String path,
required String substring,
required String newName,
}) async {
Directory(path).listSync(recursive: true).forEach((entity) async {
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());
await entity.rename(newPath);
}
}
});
}