renameSync method

  1. @override
Directory renameSync(
  1. String newPath
)
override

Synchronously renames this file system entity.

Returns a FileSystemEntity instance for the renamed entity.

Implementation

@override
Directory renameSync(String newPath) {
	deleteSync();
	final newDir = Directory(newPath);
	newDir.createSync();
	for (final entity in listSync()) {
		final segments = [
			...newDir.uri.pathSegments,
			entity.uri.pathSegments.last
		];
		final newEntity = entity.renameSync(segments.join('/'));
		if (newEntity is Directory) {
			newEntity.createSync();
		}
	}
	return newDir;
}