dirExists
Category: Directory Operations
Namespace: web.directory.dirExists
Description
Checks whether a directory exists at the specified path.
Syntax
const exists = await web.directory.dirExists({
dirPath: 'path/to/directory'
});
Parameters
- dirPath (required) - Directory path to check (relative or absolute)
Returns
Promise<boolean> - Returns a promise that resolves with true if the directory exists, false otherwise
Examples
Simple example
const exists = await web.directory.dirExists({
dirPath: 'C:\\MyFolder'
});
if (exists) {
console.log('Directory exists');
} else {
console.log('Directory does not exist');
}
Create directory if it doesn't exist
const dirPath = 'output';
const exists = await web.directory.dirExists({ dirPath });
if (!exists) {
await web.directory.createDir({ dirPath });
console.log('Directory created');
} else {
console.log('Directory already exists');
}
Use Cases
- Verify a directory exists before accessing it
- Check if a directory needs to be created
- Validate user-provided directory paths
Notes
- Returns
falseif the path exists but is a file, not a directory - Relative paths are resolved from the application executable directory
- Does not throw errors - returns
falsefor invalid or inaccessible paths