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 all files from all subdirectories.

Parameters:

Name Type Description Default
url str

URL path starting with 'nf://' to walk directories

required

Returns:

Type Description
Result

Result containing list of all file paths or error message

Source code in norfab\workers\filesharing_worker\filesharing_worker.py
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
@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 all files from all subdirectories.

    Args:
        url: URL path starting with 'nf://' to walk directories

    Returns:
        Result containing list of all file paths 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):
        files_list = []
        for root, dirs, files in os.walk(full_path):
            # skip path containing folders like __folders__
            if root.count("__") >= 2:
                continue
            root = root.replace(self.base_dir, "")
            root = root.lstrip("\\")
            root = root.replace("\\", "/")
            for file in files:
                # skip hidden/system files
                if file.startswith("."):
                    continue
                if root:
                    files_list.append(f"nf://{root}/{file}")
                else:
                    files_list.append(f"nf://{file}")
        ret.result = files_list
    else:
        ret.failed = True
        ret.errors = ["Directory Not Found"]
    return ret