createDir
Category: Directory Operations
Namespace: web.directory.createDir
Description
Creates a new directory at the specified path. Automatically creates parent directories if needed.
Syntax
const success = await web.directory.createDir({
dirPath: 'path/to/directory'
});
Parameters
- dirPath (required) - Directory path to create (relative or absolute)
Returns
Promise<boolean> - Returns a promise that resolves with true if the directory was created successfully, false otherwise
Examples
Simple example
const success = await web.directory.createDir({
dirPath: 'C:\\MyNewFolder'
});
if (success) {
console.log('Directory created successfully');
} else {
console.log('Failed to create directory');
}
Create nested directories
// Creates parent directories automatically
const success = await web.directory.createDir({
dirPath: 'output/reports/2024'
});
if (success) {
console.log('All directories created');
}
Safe directory creation
const dirPath = 'data';
// Check if it already exists
const exists = await web.directory.dirExists({ dirPath });
if (!exists) {
const success = await web.directory.createDir({ dirPath });
if (success) {
console.log('Directory created');
}
} else {
console.log('Directory already exists');
}
Use Cases
- Create output directories for generated files
- Set up folder structures for your application
- Ensure required directories exist before saving files
Notes
- Automatically creates parent directories if they don't exist
- Returns
falseif the directory already exists - Relative paths are resolved from the application executable directory
- Throws an error if the path is invalid or creation fails due to permissions