I believe the problem is that @files is not filled in
at the time the menus are being built. What you'll need to
do is find a way to hook menu selection on the first
menu, and install a handler that reconfigures the second
menu. Incidentally, you can probably rewrite
your file handling code so that it doesn't call ls and
so it will actually only find directories. Here's
a one-liner illustrating how you might look only at
directories: