DIR [directory] /S /AD > textfile.txt
Example (assuming your CD-ROM drive letter is "D"):
DIR D:\ /S /AD > textfile.txt
Don't include the brackets when you type the directory/folder. Place it inside of a text file and rename the extention to "BAT" and you have an executable "program".
/S - Checks all subdirectories
/AD - Lists folders and not files
>filename.ext - Redirects text output to a file
>>filename.ext - Adds the text to the end of an existing text file without replacing it