Skip to main content

createFile

codebolt.fs.createFile(fileName: string, source: string, filePath: string): Promise<CreateFileResponse>

Parameters

NameTypeDescription
fileNamestringThe name of the file to create.
sourcestringThe source content to write into the file.
filePathstringThe path where the file should be created.

Returns:

 Promise<CreateFileResponse>
A promise that resolves with the server response.

Example

// Let's assume you want to create a text file named hello.txt in the /home/user/documents directory with the content "Hello, world!" 

codebolt.fs.createFile('hello.txt', 'Hello, world!', '/home/user/documents');

Explaination

The codebolt.fs.createFile method is used to create a new file in a specified directory, with content provided as a string. It has three parameters:

fileName (string): This parameter specifies the name of the file to be created. The name should include the file extension (e.g., "example.txt", "data.json").

source (string): This parameter contains the content that will be written into the newly created file. It can be any string data that you want to save in the file.

filePath (string): This parameter defines the path where the file will be created. It should be a valid path in the filesystem where you have write permissions.