manage_folder
Perform folder operations in Obsidian vaults, including creating, renaming, moving, or deleting folders, to streamline organization and management of files.
Instructions
Create, rename, move, or delete a folder in the Obsidian vault
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| newPath | No | New path for the folder (required for rename and move operations) | |
| operation | Yes | The operation to perform: create, rename, move, or delete | |
| path | Yes | Path to the folder within the vault |
Implementation Reference
- src/index.ts:1196-1217 (registration)Registration of the manage_folder tool in the ListToolsRequestSchema handler, defining its name, description, and input schema for create, rename, move, delete operations.name: 'manage_folder', description: 'Create, rename, move, or delete a folder in the Obsidian vault', inputSchema: { type: 'object', properties: { operation: { type: 'string', description: 'The operation to perform: create, rename, move, or delete', enum: ['create', 'rename', 'move', 'delete'] }, path: { type: 'string', description: 'Path to the folder within the vault' }, newPath: { type: 'string', description: 'New path for the folder (required for rename and move operations)' } }, required: ['operation', 'path'], }, },
- src/index.ts:1529-1592 (handler)Primary handler function for executing manage_folder tool logic, dispatching based on operation type to appropriate folder management helpers.private async handleManageFolder(args: any) { if (!args?.operation || !args?.path) { throw new Error('Operation and path are required'); } const operation = args.operation; const folderPath = args.path; const newPath = args.newPath; switch (operation) { case 'create': await this.createFolder(folderPath); return { content: [ { type: 'text', text: `Folder created successfully at ${folderPath}`, }, ], }; case 'rename': if (!newPath) { throw new Error('New path is required for rename operation'); } await this.renameFolder(folderPath, newPath); return { content: [ { type: 'text', text: `Folder renamed from ${folderPath} to ${newPath}`, }, ], }; case 'move': if (!newPath) { throw new Error('New path is required for move operation'); } await this.moveFolder(folderPath, newPath); return { content: [ { type: 'text', text: `Folder moved from ${folderPath} to ${newPath}`, }, ], }; case 'delete': await this.deleteFolder(folderPath); return { content: [ { type: 'text', text: `Folder deleted successfully: ${folderPath}`, }, ], }; default: throw new Error(`Unknown folder operation: ${operation}`); } }
- src/index.ts:2453-2467 (helper)Supporting helper to create a folder, preferring Obsidian API with filesystem fallback.private async createFolder(folderPath: string): Promise<void> { try { // First try using the Obsidian API await this.api.post(`/folders/${encodeURIComponent(folderPath)}`); } catch (error) { console.warn('API request failed, falling back to file system:', error); // Fallback to file system if API fails const fullPath = path.join(VAULT_PATH, folderPath); if (!fs.existsSync(fullPath)) { fs.mkdirSync(fullPath, { recursive: true }); } } }
- src/index.ts:2469-2496 (helper)Supporting helper to rename a folder, preferring API with filesystem fallback including validation.private async renameFolder(folderPath: string, newPath: string): Promise<void> { try { // First try using the Obsidian API await this.api.put(`/folders/${encodeURIComponent(folderPath)}`, { newPath }); } catch (error) { console.warn('API request failed, falling back to file system:', error); // Fallback to file system if API fails const fullPath = path.join(VAULT_PATH, folderPath); const newFullPath = path.join(VAULT_PATH, newPath); if (!fs.existsSync(fullPath)) { throw new Error(`Folder not found: ${folderPath}`); } if (fs.existsSync(newFullPath)) { throw new Error(`Destination folder already exists: ${newPath}`); } // Create parent directory if it doesn't exist const parentDir = path.dirname(newFullPath); if (!fs.existsSync(parentDir)) { fs.mkdirSync(parentDir, { recursive: true }); } fs.renameSync(fullPath, newFullPath); } }
- src/index.ts:2503-2521 (helper)Supporting helper to delete a folder recursively, preferring API with filesystem fallback.private async deleteFolder(folderPath: string): Promise<void> { try { // First try using the Obsidian API await this.api.delete(`/folders/${encodeURIComponent(folderPath)}`); } catch (error) { console.warn('API request failed, falling back to file system:', error); // Fallback to file system if API fails const fullPath = path.join(VAULT_PATH, folderPath); if (!fs.existsSync(fullPath)) { throw new Error(`Folder not found: ${folderPath}`); } // Recursively delete the folder and its contents this.deleteFolderRecursive(fullPath); } }