subFolder function

void subFolder(
  1. String name
)

Creates a set of sub-folders (repository, modules, and data) within the specified main folder.

The function ensures that the directory structure under lib/[name] is created and logs success or error messages for each sub-folder. For example, calling subFolder('my_app') will create:

  • lib/my_app/repository
  • lib/my_app/modules
  • lib/my_app/data

Parameters:

  • name: The name of the main folder where the sub-folders will be created.

Implementation

void subFolder(String name) {
  // Create a Directory object for the 'repository' sub-folder within the [name] folder.
  Directory repository = Directory('lib/$name/repository');

  // Create a Directory object for the 'modules' sub-folder within the [name] folder.
  Directory modules = Directory('lib/$name/modules');

  // Create a Directory object for the 'data' sub-folder within the [name] folder.
  Directory data = Directory('lib/$name/data');

  // Create the 'repository' directory and its parent directories if they do not exist.
  repository
      .create(recursive: true)
      .then((value) => print('Sub Folder $repository created successfully'))
      .catchError((error) => print('Error creating $repository: $error'));

  // Create the 'modules' directory and its parent directories if they do not exist.
  modules
      .create(recursive: true)
      .then((value) => print('Sub Folder $modules created successfully'))
      .catchError((error) => print('Error creating $modules: $error'));

  // Create the 'data' directory and its parent directories if they do not exist.
  data
      .create(recursive: true)
      .then((value) => print('Sub Folder $data created successfully'))
      .catchError((error) => print('Error creating $data: $error'));
}