Skip to content

Modern Fs DirEntry Depth

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Filesystem › Filesystem Library › DirEntry.Depth

DirEntry.Depth

Returns how deep the entry is in a walk, 0 for the children of the folder walked.

Syntax

DirEntry.Depth( )

Notes

  • 0 for the immediate children of the walk root

Examples

#import "std/fs"
using fs

dim td as FsResultUStr = CreateTempDir( "fbdoc" )
dim as ustring dir_ = td.Value( )
WriteAllText( PathJoin( dir_, "a.txt" ), "aaa" )
WriteAllText( PathJoin( dir_, "b.txt" ), "bb" )
CreateDir( PathJoin( dir_, "sub" ) )
WriteAllText( PathJoin( dir_, "sub", "c.txt" ), "c" )

'' How far below the walk root this entry is. The root's own children
'' are depth 0.
for each r in WalkDir( dir_ )
    if r.IsOk( ) then
        print r.Value( ).Depth( ) & " " & r.Value( ).Name( )
    end if
next                         '' 0 a.txt / 0 b.txt / 0 sub / 1 c.txt

'' Under ReadDir every entry is depth 0, since it does not descend

RemoveDirAll( dir_ )

Library: Filesystem Library
Category: Filesystem
Documented under: Directories

Clone this wiki locally