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

FileDeleteTool

Deletes the requested file. Asks for confirmation before deleting.

Parameters

  • file_path (str): The path to the file to be deleted.

Returns

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

  • output (None): None.
  • exit_code (int): 0 if success, 1 if failure.

Usage

(Learn more about: FileWriteTool, FileFolderExistsTool)

import asyncio
from embedia.tools import FileWriteTool, FileDeleteTool, FileFolderExistsTool
 
file_writer = FileWriteTool()
file_delete = FileDeleteTool()
file_exists = FileFolderExistsTool()
asyncio.run(file_writer(file_path="test.txt", content="Hello World!"))
asyncio.run(file_delete(file_path="test.txt"))
resp = asyncio.run(file_exists(path="test.txt"))
print("Does text.txt exist?:", resp.output)

Running the above code prints the following:

[time: 2023-10-03T09:53:47.379648+00:00] [id: 139879836329808] [event: Tool Start]
Tool: FileWriteTool
Args: ()
Kwargs: {'file_path': 'test.txt', 'content': 'Hello World!'}
 
[time: 2023-10-03T09:53:47.382281+00:00] [id: 139879836329808] [event: Tool End]
Tool: FileWriteTool
ExitCode: 0
Output:
12
 
[time: 2023-10-03T09:53:47.383383+00:00] [id: 139879835165584] [event: Tool Start]
Tool: FileDeleteTool
Args: ()
Kwargs: {'file_path': 'test.txt'}
 
Tool: FileDeleteTool
Details: test.txt Confirm (y/n): y
 
[time: 2023-10-03T09:53:49.554808+00:00] [id: 139879835165584] [event: Tool End]
Tool: FileDeleteTool
ExitCode: 0
Output:
None
 
[time: 2023-10-03T09:53:49.555739+00:00] [id: 139879822550352] [event: Tool Start]
Tool: FileFolderExistsTool
Args: ()
Kwargs: {'path': 'test.txt'}
 
[time: 2023-10-03T09:53:49.555798+00:00] [id: 139879822550352] [event: Tool End]
Tool: FileFolderExistsTool
ExitCode: 0
Output:
False
Does text.txt exist?: False