Option Explicit

Const pfad = "%windir%"
Dim text, title, index, txt()
Dim fso, wsh, i

text = "Folder " + vbCrLf + vbCrLf
title = "wsh sample - by Gunter Born"
index = 1

Set wsh = WScript.CreateObject("WScript.Shell")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")

RecFolder index, wsh.ExpandEnvironmentStrings(pfad)

For i = 1 To UBound(txt)
    text = text + txt(i) + vbCrLf
Next

MsgBox text, vbOKOnly + vbInformation, title
WScript.quit (0)

Function RecFolder(idx, pfad)
    Dim fo, fc, i
    Set fo = fso.GetFolder(pfad)
    Set fc = fo.SubFolders
    ReDim Preserve txt(idx)
    For Each i In fc
        txt(idx) = txt(idx) + pfad + "\" + i.Name + vbCrLf
        Call RecFolder(idx + 1, pfad + "\" + i.Name)
    Next
    Set fo = Nothing
    Set fc = Nothing
End Function

