createFolder
codebolt.fs.createFolder(folderName: string, folderPath: string): Promise<CreateFolderResponse>
Creates a new folder at the specified path.
Parameters
Name | Type | Description |
---|---|---|
folderName | string | The name of the folder to create. |
folderPath | string | The path where the folder should be created. |
Returns:
Promise<CreateFolderResponse>
A promise that resolves with the server response.Examples
Basic Folder Creation
// Create a folder in a specific directory
const result = await codebolt.fs.createFolder('exampleFolder', '/home/user/documents');
console.log('Folder created:', result);
Create Folder in Current Directory
// Create a folder in the current working directory
const folderResult = await codebolt.fs.createFolder('test-folder', '.');
console.log('✅ Folder created:', folderResult);
Complete Workflow with File Operations
// Create a project structure
await codebolt.fs.createFolder('my-project', '.');
await codebolt.fs.createFolder('src', './my-project');
// Create files in the folders
await codebolt.fs.createFile('index.js', 'console.log("Hello World");', './my-project/src');
// List the created structure
const projectFiles = await codebolt.fs.listFile('./my-project', true);
console.log('Project structure:', projectFiles);
Create Multiple Folders
// Create multiple folders for different purposes
const folders = ['assets', 'components', 'utils', 'config'];
for (const folder of folders) {
try {
const result = await codebolt.fs.createFolder(folder, '.');
console.log(`✅ Created folder: ${folder}`, result);
} catch (error) {
console.error(`❌ Failed to create folder ${folder}:`, error.message);
}
}
Error Handling
try {
const result = await codebolt.fs.createFolder('test-folder', '.');
if (result.success) {
console.log('✅ Folder created successfully');
} else {
console.log('❌ Folder creation failed:', result.message);
}
} catch (error) {
console.error('Error creating folder:', error.message);
}
// Let's assume you want to create a folder named "exampleFolder" in the /home/user/documents directory.
codebolt.fs.createFolder('exampleFolder', '/home/user/documents');