Skip to content

Filesharing Service List FIles Task¤

task api name: list_files

The list_files task lists the contents of a directory at the specified URL path in a non-recursive manner. This task returns only the immediate files and subdirectories within the given path, without descending into nested directories. It's useful for browsing the structure of your file sharing repository one level at a time.

Using it from Python¤

from norfab.core.nfapi import NorFab

with NorFab(inventory="./inventory.yaml") as nf:
    client = nf.make_client()

    reply = client.run_job(
        service="filesharing",
        task="list_files",
        workers="any",
        kwargs={"url": "nf://"},
    )
    print(reply)

Using it from nfcli¤

NORFAB CLI exposes File Sharing under the file command group.

nf#man tree file.list
root
└── file:    File sharing service
    └── list:    List files
        └── url:    Directory to list content for, default 'nf://'

nf#

API Reference¤

List files in a directory.

Parameters:

Name Type Description Default
url str

URL path starting with 'nf://' to list files from

required

Returns:

Type Description
Result

Result containing list of files or error message

Source code in norfab\workers\filesharing_worker\filesharing_worker.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
@Task(
    input=ListFilesInput,
    output=ListFilesResult,
    fastapi={"methods": ["GET"]},
    agent={"enabled": False},
    mcp={
        "annotations": {
            "title": "List Files",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": False,
        }
    },
)
def list_files(self, url: str) -> Result:
    """
    List files in a directory.

    Args:
        url: URL path starting with 'nf://' to list files from

    Returns:
        Result containing list of files or error message
    """
    ret = Result(result=None)
    try:
        full_path = self._safe_path(url)
    except ValueError as e:
        ret.failed = True
        ret.errors = [str(e)]
        return ret

    if os.path.exists(full_path) and os.path.isdir(full_path):
        ret.result = os.listdir(full_path)
    else:
        ret.errors = ["Directory Not Found"]
        ret.failed = True
    return ret