0

A standard implementation of this technique is provided at: https://learn.microsoft.com/en-us/troubleshoot/windows-client/printing/add-print-directory-feature

Unfortunately it does not work for me. The Printdir.bat file is:

@echo off 
dir %1 /-p /o:gn > "%temp%\Listing" 
start /w notepad /p "%temp%\Listing"
del "%temp%\Listing"
exit

My implementation fails at the cmd level with the error:

The filename, directory name, or volume label syntax is incorrect". (The program continues and results in no file created since nothing is passed to notepad).

If run in the Windows directory, it runs fine. Adding quotes around "%1" did not help and neither did "%~1"

RogerK
  • 1
  • 2
  • 1
    Remove `@echo off` and replace `exit` by `pause`, then check in the Command Prompt window what `%1` becomes expanded to… – aschipfl May 23 '21 at 22:14
  • Replaced should be also `start /w notepad` by `%SystemRoot%\notepad.exe`. – Mofi May 23 '21 at 22:30
  • What I get is: \"C:\Users\Roger\Documents|Custom Office Templates\" – RogerK May 24 '21 at 01:52
  • What I get is: C:WINDOWS\system32>dir \"C:\Users\Roger\Documents\Custom Office Templates\" /-p /o:gn 1>"C:\Users\Roger\AppData\Local\Temp\Listing" Then the error The filename, directory name, or volume label syntax is incorrect. That is the directory that I was attempting to print. – RogerK May 24 '21 at 02:00
  • It appears that the \ after dir is the problem. That is, dir \"C:\Users\.... should be dir "C:\Users\.... However, I do not know where it is coming from and how to fix it. – RogerK May 24 '21 at 03:29
  • Run in a command prompt window `%SystemRoot%\System32\reg.exe QUERY "HKEY_CLASSES_ROOT\SOFTWARE\Classes\Directory\shell\Print_Directory_Listing\command" /ve`, [copy](https://stackoverflow.com/questions/11543578/) the output information of this registry query, [edit] your question and add the output and copied information to the question. Then we can tell you how to fix the execution of `Printdir.bat` which you have obviously registered wrong. BTW: It should be registered with full qualified file name, i.e. drive+path+name+extension and not with just file name with extension. – Mofi May 24 '21 at 09:36
  • Thanks for that excellent idea. Unfortunately, I had already edited the registry to eliminate the extra \. I have run your suggestion and received the following, now correct response: HKEY_CLASSES_ROOT\SOFTWARE\Classes\Directory\shell\Print_Directory_Listing\command (Default) REG_SZ Printdir.bat "%1\" Since I found the same incorrect instructions on four websites, it is apparent that three of the "authors" had never tried out their solution. – RogerK May 25 '21 at 15:43

1 Answers1

0

The instructions (repeated at several sites) created a file PrintDirectoryListing.reg with steps 3 and 6 creating a command Printdir.bat \"%1\" From the comments by aschipfl and Mofi, I was able to troubleshoot the activity and edit the registry, eliminate the \ before "%1" making both commands Printdir.bat "%1\". Now everything works properly. Thanks again to aschipfl and Mofi

RogerK
  • 1
  • 2