'Recursively loop through all folders in drive C: and Ouput all folders into "allFldr.txt" On Error Resume Next Set FSO = CreateObject("Scripting.FileSystemObject") Set oShell = CreateObject("WScript.Shell") Set outFile = fso.CreateTextFile("C:\allFldr.txt", True) ShowSubFolders FSO.GetFolder("C:\") outFile.Close oShell.Run "Notepad C:\allFldr.txt" Sub ShowSubFolders(Folder) For Each Subfolder in Folder.SubFolders outFile.WriteLine( Subfolder.Path ) ' <- Action here ShowSubFolders Subfolder Next End Sub