Skip to content

Commit

Permalink
Merge pull request #24 from iskandarreza/Update-ListFiles-class
Browse files Browse the repository at this point in the history
Modified ListFiles class to clearly distinguish files from directories
  • Loading branch information
FayazRahman authored Apr 30, 2023
2 parents 05d8fde + f88b77d commit faedc19
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions loopgpt/tools/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,36 @@ def run(self, file):
class ListFiles(BaseTool):
@property
def args(self):
return {}
return {
"path": "Path to the directory to list files and directories in as a string. This is a required argument.",
"recursive": "If true, list files and directories recursively. Else, list only the files and directories in the given path. This is a required argument.",
"show_hidden": "If true, show hidden files and directories. Defaults to False.",
"exclude_dirs": "If true, exclude directories from the result. Defaults to False.",
}

@property
def resp(self):
return {
"files": "list of files",
"result": "list of files and directories",
}

def run(self, *_, **__):
return os.listdir()

@property
def desc(self):
return "List files and directories in a given path. Directories end with a trailing slash."

def run(self, path, recursive, show_hidden=False, exclude_dirs=False):
entries_list = []
with os.scandir(path) as entries:
for entry in entries:
if show_hidden or not entry.name.startswith("."):
if entry.is_dir():
if not exclude_dirs:
entries_list.append(f"{entry.name}/")
if recursive:
entries_list.extend(self.run(os.path.join(path, entry.name), recursive, show_hidden, exclude_dirs)["result"])
else:
entries_list.append(entry.name)
return {"result": entries_list}


FileSystemTools = [
Expand Down

0 comments on commit faedc19

Please sign in to comment.