Skip to content

Filesharing Service Walk Task¤

task api name: walk

The walk task recursively lists files under a File Sharing URL. It returns complete nf://... URLs for each file found and skips hidden files and special directories.

Inputs¤

Parameter Required Description
url No Directory URL to walk, default nf://

Output¤

Returns a recursive list of file URLs under the requested path.

Examples¤

Walk the repository root:

nf#file walk

Walk a subdirectory:

nf#file walk url nf://templates/

Context manager:

from norfab.core.nfapi import NorFab

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

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

Direct lifecycle:

from norfab.core.nfapi import NorFab

nf = NorFab(inventory="./inventory.yaml")
try:
    nf.start()
    client = nf.make_client()

    result = client.run_job(
        service="filesharing",
        task="walk",
        workers="any",
        kwargs={"url": "nf://templates/"},
    )
    print(result)
finally:
    nf.destroy()

Filesharing Walk Command Shell Reference¤

NorFab shell supports these command options for Filesharing walk task:

nf# man tree file
root
└── file:    File sharing service
    └── walk:    Walk directory tree recursively

nf#

Python API Reference¤

Recursively list published files beneath an nf:// directory.

Hidden files and internal paths containing double-underscore directory markers are omitted from the returned namespace.

Parameters:

Name Type Description Default
url str

Root directory URL beginning with nf://.

required

Returns:

Type Description
Result

A result containing normalized nf:// file URLs. Missing

Result

directories and unsafe URLs produce failed results.

Source code in norfab\workers\filesharing_worker\local_files_tasks.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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
@Task(
    input=WalkInput,
    output=WalkResult,
    fastapi={"methods": ["GET"]},
    agent={"enabled": False},
    mcp={
        "annotations": {
            "title": "Walk Files",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": False,
        }
    },
)
def walk(self, url: str) -> Result:
    """Recursively list published files beneath an ``nf://`` directory.

    Hidden files and internal paths containing double-underscore directory
    markers are omitted from the returned namespace.

    Args:
        url: Root directory URL beginning with ``nf://``.

    Returns:
        A result containing normalized ``nf://`` file URLs. Missing
        directories and unsafe URLs produce failed results.
    """
    ret = Result(result=None)
    try:
        full_path = self._safe_path(url)
    except ValueError as exc:
        ret.failed = True
        ret.errors = [str(exc)]
        return ret

    if os.path.exists(full_path) and os.path.isdir(full_path):
        files_list = []
        for root, _directories, files in os.walk(full_path):
            if root.count("__") >= 2:
                continue
            root = root.replace(self.base_dir, "")
            root = root.lstrip("\\")
            root = root.replace("\\", "/")
            for filename in files:
                if filename.startswith("."):
                    continue
                if root:
                    files_list.append(f"nf://{root}/{filename}")
                else:
                    files_list.append(f"nf://{filename}")
        ret.result = files_list
    else:
        ret.failed = True
        ret.errors = ["Directory Not Found"]
    return ret