Search code examples
windowsbatch-filecmddir

Print directory files and folders to file from windows context menu


I'm trying to print directory content to a file, adding this feature to the windows context menu of a directory (folder). Here is the content of the .bat file

set dirpath=%1
dir %dirpath% /b /o:gn /s > "%temp%\Listing"
start /w notepad "%temp%\Listing"
del "%temp%\Listing"
exit

I have added a context menu entry inside the windows registry at this level HKEY_CLASSES_ROOT\Directory\Shell with a command pointing to the bat file.

The problem is that when I execute the command with a right-click on a folder, what is been printed is the content of the directory where that folder exists and not the content of the folder itself. What am I doing wrong? Any help appreciated.


Solution

  • It works here. Do you have quotes around the %1 in the registry. All programs except notepad (notepad is wierd) require quotes around %1 in registry commands. If not it will list wrongly or not at all folders that have a space in their full paths.

    Put pause in your file so you can see your commands being executed