We use cookies on our website.
Docs
API Reference
Tools
FolderListTool

FolderListTool

Lists the contents of the requested folder.

Parameters

  • folder (str): The path to the folder to be listed.

Returns

The return value is of the type: ToolReturn (Learn more about: ToolReturn) with the following output and exit_code:

  • output (List[str]): The contents of the folder.
  • exit_code (int): 0 if success, 1 if failure.

Usage

(Learn more about: FolderCreateTool, FileWriteTool)

import asyncio
from embedia.tools import FolderCreateTool, FolderListTool, FileWriteTool
 
folder_create = FolderCreateTool()
file_writer = FileWriteTool()
folder_list = FolderListTool()
asyncio.run(folder_create(folder="temp"))
asyncio.run(file_writer(file_path="temp/test.txt", content="Hello World!"))
resp = asyncio.run(folder_list(folder="temp"))
print("Contents of temp folder:", resp.output)

Running the above code prints the following:

[time: 2023-10-03T15:34:43.037360+00:00] [id: 139838817071504] [event: Tool Start]
Tool: FolderCreateTool
Args: ()
Kwargs: {'folder': 'temp'}
 
[time: 2023-10-03T15:34:43.037478+00:00] [id: 139838817071504] [event: Tool End]
Tool: FolderCreateTool
ExitCode: 0
Output:
None
 
[time: 2023-10-03T15:34:43.038167+00:00] [id: 139838817071824] [event: Tool Start]
Tool: FileWriteTool
Args: ()
Kwargs: {'file_path': 'temp/test.txt', 'content': 'Hello World!'}
 
[time: 2023-10-03T15:34:43.038271+00:00] [id: 139838817071824] [event: Tool End]
Tool: FileWriteTool
ExitCode: 0
Output:
12
 
[time: 2023-10-03T15:34:43.038928+00:00] [id: 139838795764624] [event: Tool Start]
Tool: FolderListTool
Args: ()
Kwargs: {'folder': 'temp'}
 
[time: 2023-10-03T15:34:43.038986+00:00] [id: 139838795764624] [event: Tool End]
Tool: FolderListTool
ExitCode: 0
Output:
['test.txt']
Contents of temp folder: ['test.txt']