WebExeBuilder Documentation

listFiles

Category: Directory Operations

Namespace: web.directory.listFiles

Description

Lists all files in a directory matching the specified criteria. Can search recursively through subdirectories.

Syntax

const files = await web.directory.listFiles({
    dirPath: 'path/to/directory',
    fileMask: '*.*',
    allDirs: false
});

Parameters

  • dirPath (required) - Directory path to search (relative or absolute)
  • fileMask (optional) - File pattern to match (default: '*.*' for all files). Examples: '*.txt', '*.jpg', 'data*.json'
  • allDirs (optional) - Boolean, if true searches recursively through all subdirectories (default: false)

Returns

Promise<string[]> - Returns a promise that resolves with an array of full file paths

Examples

List all files in directory

const files = await web.directory.listFiles({
    dirPath: 'C:\\MyFolder'
});
console.log('Files found:', files);
// Output: ['C:\\MyFolder\\file1.txt', 'C:\\MyFolder\\file2.jpg']

List specific file types

// Find all text files
const textFiles = await web.directory.listFiles({
    dirPath: 'documents',
    fileMask: '*.txt'
});

console.log('Text files:', textFiles);

Recursive search

// Search all subdirectories for images
const images = await web.directory.listFiles({
    dirPath: 'photos',
    fileMask: '*.jpg',
    allDirs: true
});

console.log('Found', images.length, 'images');

Use Cases

  • List all files in a directory for processing
  • Find specific file types (e.g., all images, all documents)
  • Search recursively through folder structures
  • Build file browsers or file selection interfaces

Notes

  • Returns full file paths only, not directory paths
  • Use web.directory.dirExists() to check if a path is a directory
  • Relative paths are resolved from the application executable directory
  • The fileMask parameter supports wildcards: * (any characters) and ? (single character)
  • When allDirs is true, searches all subdirectories recursively