createFile function

void createFile(
  1. FileModel file,
  2. String path, {
  3. bool force = false,
})

Implementation

void createFile(FileModel file, String path,{bool force = false}) {

  final createdFile = File("$path${file.name}");

  if (createdFile.existsSync() && !force) {
    debugPrint('\x1B[31mError: The file $path${file.name} already exists\x1B[0m');

    return;
  }

  if(createdFile.existsSync()){
    debugPrint('\u001b[32mFile  "${file.name}" deleted successfully\u001b[0m');
  }


  createdFile.createSync(recursive: true,exclusive: true);

  createdFile.writeAsStringSync("\n\n\n\n${file.content}");
  debugPrint('\u001b[32mDone: file created successfully "${file.name}"\u001b[0m');
}