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

FileCopyTool

Copies a file from one location to another, overwrites if destination exists.

Parameters

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

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: FileReadTool, FileWriteTool)

import asyncio
from embedia.tools import FileWriteTool, FileCopyTool, FileReadTool
 
file_writer = FileWriteTool()
file_copy = FileCopyTool()
file_reader = FileReadTool()
asyncio.run(file_writer(file_path="test.txt", content="Hello World!"))
asyncio.run(file_copy(file_path="test.txt", destination="test2.txt"))
resp = asyncio.run(file_reader(file_path="test2.txt"))
print("Contents of text2.txt:", resp.output)

Running the above code prints the following:

[time: 2023-10-03T15:12:32.893419+00:00] [id: 139737504891152] [event: Tool Start]
Tool: FileWriteTool
Args: ()
Kwargs: {'file_path': 'test.txt', 'content': 'Hello World!'}
 
[time: 2023-10-03T15:12:32.893656+00:00] [id: 139737504891152] [event: Tool End]
Tool: FileWriteTool
ExitCode: 0
Output:
12
 
[time: 2023-10-03T15:12:32.894756+00:00] [id: 139737516023184] [event: Tool Start]
Tool: FileCopyTool
Args: ()
Kwargs: {'file_path': 'test.txt', 'destination': 'test2.txt'}
 
[time: 2023-10-03T15:12:32.895022+00:00] [id: 139737516023184] [event: Tool End]
Tool: FileCopyTool
ExitCode: 0
Output:
test2.txt
 
[time: 2023-10-03T15:12:32.895875+00:00] [id: 139737515682640] [event: Tool Start]
Tool: FileReadTool
Args: ()
Kwargs: {'file_path': 'test2.txt'}
 
[time: 2023-10-03T15:12:32.896017+00:00] [id: 139737515682640] [event: Tool End]
Tool: FileReadTool
ExitCode: 0
Output:
Hello World!
Contents of text2.txt: Hello World!