Updated 2012-09-01 02:50:59 by RLE

Richard Suchenwirth 2006-04-05 - A VFS (virtual filesystem) is an elaborate piece of engineering. This page is not. It's just an experiment in how to map tree-structured data in a kind of filesystem with directories. (The purpose is to provide an analogon to glob, for opening Tree nodes for such a structure on demand.) For this, each "directory" is implemented as an array element, which contains its children with full path.
 proc mkvfs {_arr data} {
   upvar 1 $_arr arr
   foreach item $data {
      set dir  [file dir $item]
      if ![info exists arr($dir)] {set arr($dir) {}}
      if {$dir ne "/"} {mkvfs arr $dir}
      if {[lsearch -exact $arr($dir) $item]<0} {
         lappend arr($dir) $item
      }
   }
 }

Test:
 set data {
   /foo/f1/g1
   /foo/f1/g2
   /foo/f2/g3
   /foo/f2/g4
   /bar/b1/hello
   /bar/b1/world
   /bar/b2/test
   /bar/b2/again
 }

 % mkvfs arr $data
 % parray arr
 arr(/)       = /foo /bar
 arr(/bar)    = /bar/b1 /bar/b2
 arr(/bar/b1) = /bar/b1/hello /bar/b1/world
 arr(/bar/b2) = /bar/b2/test /bar/b2/again
 arr(/foo)    = /foo/f1 /foo/f2
 arr(/foo/f1) = /foo/f1/g1 /foo/f1/g2
 arr(/foo/f2) = /foo/f2/g3 /foo/f2/g4

SEH 20060405 -- The Tclvfs package has a sample namespace virtual filesystem which uses namespaces to manage the tree-structured file/directory data. It may provide the kind of function you're looking for.

LV I suspect that Richard is not seeking a function, but instead experimenting with how aspects of various advanced features of Tcl could be emulated, in part, in vanilla Tcl.

RJ He's Playing VFS, IMO.