search_files
Find files on Windows systems using wildcard patterns to locate documents, media, or data in specified directories.
Instructions
搜索文件(支持通配符)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory | Yes | 搜索目录 | |
| pattern | Yes | 搜索模式(如 *.txt) |
Implementation Reference
- src/tools/filesystem.js:211-222 (handler)The handler function that executes the file search using Windows 'dir' command via child_process.execAsync to list files matching the pattern.async searchFiles(directory, pattern) { try { const { stdout } = await execAsync( `dir /s /b "${path.join(directory, pattern)}"`, { shell: 'cmd.exe' } ); const files = stdout.trim().split('\n').filter(f => f); return { success: true, files, count: files.length }; } catch (error) { return { success: false, error: error.message, files: [] }; } }
- src/tools/filesystem.js:94-105 (schema)Input schema definition for the 'search_files' tool, specifying required 'directory' and 'pattern' parameters.{ name: 'search_files', description: '搜索文件(支持通配符)', inputSchema: { type: 'object', properties: { directory: { type: 'string', description: '搜索目录' }, pattern: { type: 'string', description: '搜索模式(如 *.txt)' }, }, required: ['directory', 'pattern'], }, },
- src/tools/filesystem.js:115-136 (registration)The executeTool method dispatches 'search_files' calls to the searchFiles handler via switch case.async executeTool(name, args) { switch (name) { case 'read_file': return await this.readFile(args.path); case 'write_file': return await this.writeFile(args.path, args.content); case 'list_directory': return await this.listDirectory(args.path); case 'create_directory': return await this.createDirectory(args.path); case 'delete_file': return await this.deleteFile(args.path); case 'copy_file': return await this.copyFile(args.source, args.destination); case 'move_file': return await this.moveFile(args.source, args.destination); case 'search_files': return await this.searchFiles(args.directory, args.pattern); default: throw new Error(`未知工具: ${name}`); } }
- src/tools/filesystem.js:109-113 (registration)The canHandle method checks if the tool module handles 'search_files' by including it in the tools array.canHandle(toolName) { const tools = ['read_file', 'write_file', 'list_directory', 'create_directory', 'delete_file', 'copy_file', 'move_file', 'search_files']; return tools.includes(toolName); }