If you have existing files inside a directory and want to move them to subdirectories FileSystemToolkit returns an error when using the move tool:Error: [Errno 2] No such file or directory .
Looking inside the implementation for the move tool we can see that it does not check if destination folder exists and don't try to create subfolders as needed:
try:
# shutil.move expects str args in 3.8
shutil.move(str(source_path_), destination_path_)
return f"File moved successfully from {source_path} to {destination_path}."
except Exception as e:
return "Error: " + str(e)
The same happens for copy.py, but write.py (tool to create a new file) creates subdirectories.
This is useful for when trying to reorganize files that already exists inside a parent directory into one or more subdirectories.
A solution to that would be to check if destination directory exists before trying to move the file, and if it doesn't exist create subdirectories. But for that we need to create a new toolkit based on the official LangChain implementation.
If you have existing files inside a directory and want to move them to subdirectories FileSystemToolkit returns an error when using the move tool:
Error: [Errno 2] No such file or directory
. Looking inside the implementation for the move tool we can see that it does not check if destination folder exists and don't try to create subfolders as needed:.venv/lib64/python3.12/site-packages/langchain_community/tools/file_management/move.py (line 49):
The same happens for copy.py, but write.py (tool to create a new file) creates subdirectories.
This is useful for when trying to reorganize files that already exists inside a parent directory into one or more subdirectories.
A solution to that would be to check if destination directory exists before trying to move the file, and if it doesn't exist create subdirectories. But for that we need to create a new toolkit based on the official LangChain implementation.