selectFolder
Category: Dialog Operations
Namespace: web.dialogs.selectFolder
Description
Display a native Windows folder selection dialog that allows users to browse and select a directory. Returns the full path to the selected folder, or an empty string if cancelled.
Syntax
const folderPath = await web.dialogs.selectFolder({
title: string
});
Parameters
- title (optional) - Dialog window title. Default: "Select Folder"
Returns
Promise<string> - Full path to selected folder, or empty string "" if cancelled
Example
Simple example
const folderPath = await web.dialogs.selectFolder();
if (folderPath) {
console.log('Selected:', folderPath);
}
Practical example
const folderPath = await web.dialogs.selectFolder({
title: 'Select Output Folder'
});
if (folderPath) {
const files = await web.directory.listFiles({ path: folderPath });
console.log(`Folder contains ${files.length} files`);
} else {
console.log('Folder selection cancelled');
}
Advanced example
async function processFolderFiles() {
const folderPath = await web.dialogs.selectFolder({
title: 'Select Folder to Process'
});
if (!folderPath) {
alert('No folder selected');
return;
}
// listFiles returns full paths; fileMask filters by extension
const textFiles = await web.directory.listFiles({
dirPath: folderPath,
fileMask: '*.txt',
allDirs: false
});
console.log(`Processing ${textFiles.length} text files...`);
for (const fullPath of textFiles) {
// fullPath is already absolute (e.g. "C:\MyFolder\file.txt")
const content = await web.files.readTextFile({ filePath: fullPath });
// Process file content
const processed = content.toUpperCase();
// Build output path alongside the original file
const fileName = fullPath.split('\\').pop();
await web.files.writeTextFile({
filePath: `${folderPath}\\processed_${fileName}`,
contents: processed
});
}
alert(`Processed ${textFiles.length} files in ${folderPath}`);
}
Use Cases
- Let users select output directories
- Choose folders for batch operations
- Select project directories
- Pick backup locations
- Choose installation directories
- Select folders to scan or process
- Browse for data directories
- Pick locations for exports or archives
Error Handling
Returns empty string "" if user cancels. Always check before proceeding.
const folderPath = await web.dialogs.selectFolder({
title: 'Select Folder'
});
if (!folderPath) {
console.log('Folder selection cancelled');
return;
}
// Proceed with folder operations
const files = await web.directory.listFiles({ path: folderPath });
Performance Tips
- Provide clear, descriptive dialog titles
- Always handle the cancel case (empty string)
- Verify folder exists before operations
- Use with directory APIs for folder operations
- Check folder permissions before writing
Related Methods
web.dialogs.openFile()- Open file dialogweb.dialogs.saveFile()- Save file dialogweb.directory.listFiles()- List folder contentsweb.directory.dirExists()- Check if folder existsweb.directory.createDir()- Create new folder
Notes
- Native Windows folder browser dialog
- Returns full absolute path (e.g., "C:\Users\Documents\MyFolder")
- Returns empty string
""on cancel (not null) - User can create new folders from the dialog
- Dialog remembers last used directory
- Path uses backslashes on Windows (e.g., "C:\Folder\Subfolder")
- No initialDir parameter - dialog starts at last used location