To create the entry in the context menu it's necessary to first create a batch file. A batch file is a text file that contains a sequence of commands for a computer operating system and uses the .bat extension. The format for the .bat file is:
dir /a /-p /o:gen >filelisting.txt
The name of the .txt file can be whatever you like. In this example, I've used filelisting.txt, but it could just as easily be filelist, listoffiles, namedfiles, or even Wally if you enjoy the bizarre in your filenaming schemes. Once you've decided on the filename, create the file in Notepad.
Save the file in your WINDOWS folder , making sure to use the .bat extension and not the default .txt extension. It's important to set "Save as type" to All Files and "Encoding:" to ANSI.
Now that we have the .bat file created, the next step is to make it functional and easily accessible by integrating it into the context menu that opens when a right click is executed. Open Windows Explorer and choose Tools ? Folder Options ? File Types tab ? Folder ? Advanced ? New, to open the New Action box.
In the Action box, type the name that you want to appear in the context menu. Once again, you have wide latitude in choices; something like Create File Listing will probably be most useful, but you can name yours something more confusing if you like. Browse to the location of the .bat file you created, and select it in the box labeled "Application used to perform action." Click OK, and you'll see that Create File Listing (or whatever you chose as an action name) has been added as one of the Actions in the Edit File Type window, as shown in . Do the standard Windows dance of clicking OK again to close all the open windows.
If for any reason you want to remove the Create File Listing entry from the context menu, you must edit the Registry. Navigate to HKEY_CLASSES_ROOT\Folder\shell\Create_File_Listing and delete the Create_File_Listing key in the left pane. Close regedit and reboot to complete removal.
dir /s /on /b /a:d > c:\folderlist.txt
/s = sub directory
/on = order by name
/b = bare format
/a:d = display only directories
> = output to file
Copy and paste the two lines after the colon into your batch file. You can create an action for each one if desired. If you modify these please note the space after each switch.
Main folders and sub-folders [Preferred]:
dir /s /on /b /a:d >FolderList.txt
FolderList.txt
Main Folders only:
dir /a /-p /o:gen >FolderList.txt
FolderList.txt
Include Files:
dir /s /a /-p /o:gen >FolderList.txt
FolderList.txt
Source