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

FolderSearchTool

Searches for the location of a requested file in a folder and its subfolders.

Parameters

  • folder (str): The path to the folder to be searched.
  • filename (str): The name of the file to be searched for.

Returns

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

  • output (str): The path to the file if found, None if not found.
  • exit_code (int): 0 if success, 1 if failure.

Usage

(Learn more about: FolderCreateTool, FileWriteTool)

import asyncio
from embedia.tools import FolderCreateTool, FolderSearchTool, FileWriteTool
 
folder_create = FolderCreateTool()
file_writer = FileWriteTool()
folder_search = FolderSearchTool()
asyncio.run(folder_create(folder="temp"))
asyncio.run(folder_create(folder="temp/temp2"))
asyncio.run(file_writer(file_path="temp/test6.txt", content="Hello World!"))
asyncio.run(file_writer(file_path="temp/temp2/test.txt", content="Hello World!"))
resp = asyncio.run(folder_search(folder="temp", filename="test.txt"))
print("Location of test.txt:", resp.output)

Running the above code prints the following:

[time: 2023-10-03T15:53:12.602188+00:00] [id: 140291493098576] [event: Tool Start]
Tool: FolderCreateTool
Args: ()
Kwargs: {'folder': 'temp'}
 
[time: 2023-10-03T15:53:12.602310+00:00] [id: 140291493098576] [event: Tool End]
Tool: FolderCreateTool
ExitCode: 0
Output:
None
 
[time: 2023-10-03T15:53:12.602944+00:00] [id: 140291493098576] [event: Tool Start]
Tool: FolderCreateTool
Args: ()
Kwargs: {'folder': 'temp/temp2'}
 
[time: 2023-10-03T15:53:12.603028+00:00] [id: 140291493098576] [event: Tool End]
Tool: FolderCreateTool
ExitCode: 0
Output:
None
 
[time: 2023-10-03T15:53:12.603759+00:00] [id: 140291493881744] [event: Tool Start]
Tool: FileWriteTool
Args: ()
Kwargs: {'file_path': 'temp/test6.txt', 'content': 'Hello World!'}
 
[time: 2023-10-03T15:53:12.603945+00:00] [id: 140291493881744] [event: Tool End]
Tool: FileWriteTool
ExitCode: 0
Output:
12
 
[time: 2023-10-03T15:53:12.604429+00:00] [id: 140291493881744] [event: Tool Start]
Tool: FileWriteTool
Args: ()
Kwargs: {'file_path': 'temp/temp2/test.txt', 'content': 'Hello World!'}
 
[time: 2023-10-03T15:53:12.604559+00:00] [id: 140291493881744] [event: Tool End]
Tool: FileWriteTool
ExitCode: 0
Output:
12
 
[time: 2023-10-03T15:53:12.605110+00:00] [id: 140291469205392] [event: Tool Start]
Tool: FolderSearchTool
Args: ()
Kwargs: {'folder': 'temp', 'filename': 'test.txt'}
 
[time: 2023-10-03T15:53:12.605226+00:00] [id: 140291469205392] [event: Tool End]
Tool: FolderSearchTool
ExitCode: 0
Output:
temp/temp2/test.txt
Location of test.txt: temp/temp2/test.txt