• Announcements

    • xper

      MSFN Sponsorship and AdBlockers!   07/10/2016

      Dear members, MSFN is made available via subscriptions, donations and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, become a site sponsor and ads will be disabled automatically and by subscribing you get other sponsor benefits.
kbdavis

Add Command in Context Menu?

29 posts in this topic

I need help adding a command to print the directory to the context menu (the right-click menu).

I have created a .bat file in the windows directory with the following information:

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

Now I just need to figure out the option to execute this .bat file by right-clicking in the directory I want to print.

Any ideas?

Edited by kbdavis
0

Share this post


Link to post
Share on other sites

Take a look in HKEY_CLASSES_ROOT\Directory\shell (or similar) for an example to copy.

If the batch file is named printdir.bat, it might look something like this:


REGEDIT4

[HKEY_CLASSES_ROOT\Directory\shell\Print]
@="&Print Directory"

[HKEY_CLASSES_ROOT\Directory\shell\Print\command]
@="C:\\WINDOWS\\printdir.bat \"%1\""

Edit: Added missing "REGEDIT4" to sample for clarity.

Edited by jumper
0

Share this post


Link to post
Share on other sites

Right now I can't find an older post I made about this, but I was researching this a while back. There are two main methods ...

[HKEY_LOCAL_MACHINE\Software\Classes\Directory\Shell\xxx]

[HKEY_LOCAL_MACHINE\Software\Classes\Folder\Shell\xxx]

It looks to me that using FOLDER is preferable because I am pretty sure that DIRECTORY is not processed when right-clicking hidden/system folders.

Furthermore, I noticed that on Win9x, when using both methods they appear consecutively in the list. By inserting a label into dummy entries I was able to get horizontal lines to show up directly inside the right-click menu, and this is roughly how Win9x displayed it ...

===[ BEGIN Shell:Directory ]==================

item

item

item

===[ END Shell:Directory ]==================

===[ BEGIN Shell:Folder ]=====================

item

item

item

===[ END Shell:Folder ]=====================

However, on WinXP, so far the label for DIRECTORY does not show up, but the label for FOLDER does. Interestingly, the items are co-mingled together. I will need more time to experiment though. Consider these preliminary observations. I'll try to get some screenshots next time.

0

Share this post


Link to post
Share on other sites

Take a look in HKEY_CLASSES_ROOT\Directory\shell (or similar) for an example to copy.

If the batch file is named printdir.bat, it might look something like this:


[HKEY_CLASSES_ROOT\Directory\shell\Print]
@="&Print Directory"

[HKEY_CLASSES_ROOT\Directory\shell\Print\command]
@="C:\\WINDOWS\\printdir.bat \"%1\""

I attempted this method, also using the other poster's method with the "folder" instead of directory, with no success. Any troubleshooting ideas?

*By the way, thanks for the quick response for both posters!

EDIT:

Please note that your method may work, I just have limited knowledge of editing the registry and I may have made the error with the execution part.

Edited by kbdavis
0

Share this post


Link to post
Share on other sites
I attempted this method, also using the other poster's method with the "folder" instead of directory, with no success. Any troubleshooting ideas?

Please post the exact registry scripts you tried. Usually it is just a matter of getting the quotes and backslash characters "escaped" correctly. This just means using the proper syntax so that REGEDIT actually inserts the expected string into the registry.

0

Share this post


Link to post
Share on other sites
I attempted this method, also using the other poster's method with the "folder" instead of directory, with no success. Any troubleshooting ideas?

Please post the exact registry scripts you tried. Usually it is just a matter of getting the quotes and backslash characters "escaped" correctly. This just means using the proper syntax so that REGEDIT actually inserts the expected string into the registry.

I attached a couple of screen shots to show you how I applied the registry edits.

post-374731-0-93074000-1363064191_thumb.

post-374731-0-53653100-1363064198_thumb.

0

Share this post


Link to post
Share on other sites
I attached a couple of screen shots to show you how I applied the registry edits.

It's exactly like I said, the error is in the REG script ( or you manually entered the REG script text ). The 2nd left photo clearly shows the error right away with the doubled backslashes and other stuff.

For those to exist as they appear in the photo, you either literally entered the escaped ( double backslash ) strings from the REG text file into the registry via the REGEDIT dialog boxes, or, your imported REG text file actually has quadruple backslashes "\\\\". If you were to now export that key you will see them.

Anyway, this is what you now should import into REGEDIT ( don't copy/paste the lines into REGEDIT! ) ...

REGEDIT4

[-HKEY_CLASSES_ROOT\Directory\Shell\Print]

[HKEY_CLASSES_ROOT\Directory\Shell\Print]

@="&Print Directory"

[HKEY_CLASSES_ROOT\Directory\Shell\Print\Command]

@="\"C:\\Windows\\Printdir.bat\" \"%1\""

I repeat, that chunk of text should be saved as a .REG file and then imported ( or dropped onto ) REGEDIT.

P.S. I would personally use "FOLDER" instead of "DIRECTORY".

EDIT: correction, I meant the 1st photo has the incorrect \Command] strings.

Edited by CharlotteTheHarlot
0

Share this post


Link to post
Share on other sites

Thanks for the tip and the quick reply. The registry edit is working now.

Now I have a new problem

See the attached screenshot of the issue. We know that the registry tweak worked because it directed to the PrintDir.bat file and actually managed to open notepad as instructed. So, I believe my issue now lies in the instruction block of the PrintDir.bat file. Below I have put in the code of the file, and would like to know if you know a way to tweak this the proper way...

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

Thanks for all the help, we are getting somewhere now!

post-374731-0-67664600-1363148029_thumb.

0

Share this post


Link to post
Share on other sites

Remove the angled double-quotes. This works for me:


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

Use normal double-quotes if your temp path has a space in it (mine doesn't).

Tip: don't use @echo off when debugging!

Also: I second the recommendation to try using "Folder" instead of "Directory" again.

0

Share this post


Link to post
Share on other sites
Thanks for the tip and the quick reply. The registry edit is working now.

Now I have a new problem

See the attached screenshot of the issue. We know that the registry tweak worked because it directed to the PrintDir.bat file and actually managed to open notepad as instructed. So, I believe my issue now lies in the instruction block of the PrintDir.bat file. Below I have put in the code of the file, and would like to know if you know a way to tweak this the proper way...

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

Some suggestions ...

(0) Personally I prefer a hardcoded path for the temp folder because the global %temp% variable can easily get changed either by accident or malware.

(1) Likewise with temp filenames, I also prefer filename.ext rather than just filename to avoid a possible directory name collision. But that's just me.

(2) For absolute precision I prefer %1\*.* instead of just %1 because I don't trust the shell ( context menu ) to supply the trailing backslash. Indeed I just checked on WinXP and it does not supply the backslash. So if a file exists that matches the name of the directory you are right-clicking there will be a collision and instead of getting a directory listing you will get the name and size of the file. Also note, as jumper mentioned, there is the possibility of spaces in the folder name. But in the example registry string I gave you above, it is already handled by the escaped string ... @="\"C:\\Windows\\Printdir.bat\" \"%1\""

(3) I don't think you need the colon ":" in the DIR command sort switch. Try using just ... /ogn

(4) You are using the reverse prefix "-" on the /p pause ( did you instead want it to be on the /o sort order? ) And I am confused why it should be paused when it is intended to be printed. Or, perhaps you have DIRCMD defaults and this is intended to reverse that and prevent pausing?

(5) You are using a temp file and then deleting it, thus you need the START /w which makes sense, but the whole process is unnecessary. Since you are using the overwrite redirection operator ">" ( rather than the append ">>" ), the file is essentially deleted anyway. Scrap that concept and forget the temp file even exists and just launch NotePad. When it closes you can ignore the temp file ( no need to delete it ) because it will get overwritten later. It also may prove helpful to be able to refer back to the exact file you printed if something looks awry in the printout.

(6) I wouldn't even bother with the @echo off since without it you might get some echoed debugging clues in the CMD window if you should ever wind up in a hang situation.

(7) I don't recall needing EXIT for context menu launched batch files, but I know that using CLS after a blank line is an old trick to close stubborn CMD windows. There is a linefeed after CLS also.

So I would try this one ( depending on what that /p DIR switch is all about ) ...

dir %1\*.* /ogn /-p > C:\Temp\Listing.txt
notepad.exe /p C:\Temp\Listing.txt

cls

EDIT: almost forgot, you may want to add /a to list all files ( including hidden ) ...

dir %1\*.* /a /ogn /-p > C:\Temp\Listing.txt

Also, I always try to limit the failure vectors and specify exact filenames ( e.g., notepad.exe rather than just notepad ) to rule out malware cases like notepad.bat. Probably the best thing is to hardcode to C:\Windows\Notepad.exe to be completely safe!

Edited by CharlotteTheHarlot
0

Share this post


Link to post
Share on other sites

It works perfect. Thanks for the help and the speedy replies!

0

Share this post


Link to post
Share on other sites
It works perfect. Thanks for the help and the speedy replies!

Glad you have it sorted out. You should consider posting it here in its final form for others that might want to use PrintDir from the context menu. Perhaps you can also test it on a Hidden and System folder as well.

P.S. You might want to carefully audit your registry for other instances of double backslashes. If they exist they can stop other programs from working. I just started a separate thread about such things over here.

0

Share this post


Link to post
Share on other sites

Ok here is the final product instructions, thanks to the help of CharlotteTheHarlot & Jumper for their contributions:

Open up notepad, copy and paste this code:

REGEDIT4

[-HKEY_CLASSES_ROOT\Directory\Shell\Print]
[HKEY_CLASSES_ROOT\Directory\Shell\Print]
@="&Print Directory"
[HKEY_CLASSES_ROOT\Directory\Shell\Print\Command]
@="\"C:\\Windows\\Printdir.bat\" \"%1\""

Name it anything as long as you change the extension from .txt to .reg

Open the reg file you just created and apply the changes to the registry.

Next

In a new notepad, copy and paste this code:

dir %1\*.* /a /ogn /-p > C:\Temp\Listing.txt
C:\Windows\notepad.exe /p C:\Temp\Listing.txt

cls

Save this file as PrintDir.bat. This needs to be saved in your windows directory.

Afterwards, I would restart your computer, mainly because I don't trust anything to get loaded in the memory (hence, the new registry change you just did). You can also try killing the explorer.exe process then starting it again.

Again, the credit for this goes to CharlotteTheHarlot & jumper. I am just here to condense all the suggestions they gave to make this happen. Thanks again for the help, and hope this thread helps others who are needing to print a directory.

0

Share this post


Link to post
Share on other sites

Does anyone know the Reg Key for the file Command Context Menu for files

I added this for folders and it works, thank you for the information on how to do it.

post-5386-0-60886200-1363547588_thumb.pn

I have the DeleteIt to work from the SendTo Folder but would like it on the context menu underneath the create shortcut

post-5386-0-29332200-1363548010_thumb.pn

Is it possible to have the icon appear with the Delete It on the context menu, like the Microsoft Security Essentials

0

Share this post


Link to post
Share on other sites

Since you mentioned displaying an icon I think you might be referring to "the other kind" of context menu entry. The two main methods that I know are ...

Context Menu using "Shell" ...

[HKEY_LOCAL_MACHINE\Software\Classes\xxx\Shell\yyy]

[HKEY_LOCAL_MACHINE\Software\Classes\xxx\Shell\yyy\Shell]

[HKEY_LOCAL_MACHINE\Software\Classes\xxx\Shell\yyy\Shell\Open]

[HKEY_LOCAL_MACHINE\Software\Classes\xxx\Shell\yyy\Shell\Open\Command]

@="Drive:\\Directory\\Filename.exe < parameters >" <--- requires careful escaping of parameters and quotes

Context Menu using "ShellEx" ...

[HKEY_LOCAL_MACHINE\Software\Classes\xxx\ShellEx\ContextMenuHandlers\yyy]

@="zzz" <--- usually a {CLSID}, this is a direct pointer to another registry key ...

[HKEY_LOCAL_MACHINE\Software\Classes\CLSID\zzz]

@="Some Description"

[HKEY_LOCAL_MACHINE\Software\Classes\CLSID\zzz\InProcServer32]

@="Drive:\\Directory\\Filename.dll"

"ThreadingModel"="Apartment"

xxx is a well-known shell object. This list is from the link mentioned below, but might not be complete ...

* ...................... All files

AllFileSystemObjects ... All files and file folders

Folder ................. All folders

Directory .............. File folders

Directory\Background ... File folder background

Drive .................. All drives in MyComputer, such as "C:\"

Network ................ Entire network (under My Network Places)

Network\Type\# ......... All objects of type #

NetShare ............... All network shares

NetServer .............. All network servers

network_provider_name .. All objects provided by network provider "network_provider_name"

Printers ............... All printers

AudioCD ................ Audio CD in CD drive

DVD .................... DVD drive (Windows 2000)

yyy of course is merely an arbitrary label sometimes ( :lol: ) used to help determine what this handler does.

The "Shell" method is a really simple way from the GUI to pass the target ( the object right-clicked ) to an external program with some rudimentary ability to define some parameters for the external program and then launch it. I think of it as roughly equivalent to a batch file. This method does not allow icons to appear.

The "ShellEx" method is complicated in that a handler DLL needs to exist. By using a canned set of code in a DLL they can offer many more procedures at runtime, including displaying of icons and sub-flyout menus, etc. Note that ShellEx itself has a variety of methods of interacting with the shell, "ContextMenuHandlers" is only one of them. There are others like "DragDropHandlers" or "PropertySheetHandlers". I don't have complete list at the moment.

From what you say it sounds like you have a Shell handler. So it will not be able to have an icon. However if this program "Delete It" includes a context menu DLL, it very well may have an icon embedded and merely needs to be registered.

Creating Shell Extension Handlers (Windows) ( MSDN )

P.S. I can't find it but there is a thread in the Win9x forum that explores a particular 3rd party ShellEx launched DLL that allows someone to define icons and a variety of other features in the context menu. Some of these things I mention above I also mentioned in that thread..

Edited by CharlotteTheHarlot
0

Share this post


Link to post
Share on other sites

After a little research I have figured out that the program I was trying to recall was/is called Fast Explorer by Alex Yakovlev and Serge Kolesnikov.

It was hosted at http://thesoftpro.tripod.com/downloads/fe/index.htm but appears to have vanished.

I located a page in Wayback here ... http://web.archive.org/web/20100125014241/http://thesoftpro.tripod.com/downloads/fe/index.htm

The last dated page seems to be 2008-08-24 but I have all the files and pages saved from their website as of 2010-01-26. Not sure when they went offline though. Screencap of the top of the first page ...

fastexplorerwebpagep1.jpg

If you want to see the middle and bottom of that page open these images: part-2, part-3 ( it was too large for a single bitmap ).

P.S. I still cannot find the MSFN thread where we had discussed it.

EDIT: typo

Edited by CharlotteTheHarlot
0

Share this post


Link to post
Share on other sites

Just wanted to mention a short reference I found, by Raymond Chen on his blog ...

What is the difference between the Folder and Directory (and other special) progids? ( 2007-08-02 )

When you're installing your shell extension, you need to know which progid to hang it off of inside HKEY_CLASSES_ROOT. We'll start with the title question and then move on to other predefined (but perhaps not well-known) progids.

  • "Folder" is the progid for any shell folder. It could be a virtual folder (like Control Panel) or a file system folder (like C:\WINDOWS).
  • "Directory" is the progid for file system folders. This is a subset of "Folder".
  • "*" is the progid for all files. Doesn't matter what the extension is.
  • "." (that's a single period) is the progid for files without any extension.
  • "AllFileSystemObjects" is the union of "*" and "Directory". It is the progid for all files and for file system directories.

The statement: "Directory" is a subset of "Folder" seems to verify something I suggested earlier in this thread about slight differences in what handlers show up when right-clicking either of those two types. I just need to confirm the details of HIDDEN and/or SYSTEM folders being excluded from "Directory".

0

Share this post


Link to post
Share on other sites

I was able to add Delete It to the context menu where Open and Edit are located.

Thank you , I used * Reg key to add Delete it :thumbup

post-5386-0-85651200-1364496121_thumb.pn

How To Add

1:\ Copy Application to Windows or Windows\Systen32, I used the Window folder

2:\ Open Reg Edit Expand HKEY_CLASSES_ROOT\*

3:\ Add a Key inside the Registry Shell Folder , this is also the name on the context menu Example Delete It

4:\ Create a key in inside of step 3 called command and fill in the Default with Example C:\Windows\DeleteIt.exe "%1"

Reg Key Delete It Added

post-5386-0-84069500-1364496292_thumb.pn

0

Share this post


Link to post
Share on other sites

Anyone interested in INF format? You can mount the WIM and apply this and have 7 "remember" the settings I suppose.

The line for directory contents is this:

HKCR,"Folder\Shell\List Contents to text file\command",,,"%11%\cmd.exe /C DIR ""%1"" /B /O /S>""%1""""_contents list.txt"""

It makes a printable file. My INF below adds a few useful items I use all the time in 7 like using the contig utility for defragging and remember those instructions all over the 'net to make a "god mode" icon on the desktop? That's in here too but I call it 'expanded control panel' (you'll see what I mean). Edit it as you will....



[version]
Signature="$Windows NT$"

[DefaultInstall]
AddReg = ContextMenu

[ContextMenu]

; Add "command-prompt-here" functionality when right-clicking a directory
HKCR,"Drive\Shell\Command Prompt Here\command",,,"%11%\cmd.exe /k cd ""%1"""
HKCR,"Directory\Shell\Command Prompt Here\command",,,"%11%\cmd.exe /k cd ""%1"""

;
HKCR,"*\shell\runas",,,"Take Ownership"
HKCR,"*\shell\runas","NoWorkingDirectory",,""
HKCR,"*\shell\runas\command",,,"cmd.exe /c takeown /f ""%1"" && icacls ""%1"" /grant administrators:F"
HKCR,"*\shell\runas\command","IsolatedCommand",,"cmd.exe /c takeown /f ""%1"" && icacls ""%1"" /grant administrators:F"
HKCR,"Directory\shell\runas",,,"Take Ownership"
HKCR,"Directory\shell\runas","NoWorkingDirectory",,""
HKCR,"Directory\shell\runas\command",,,"cmd.exe /c takeown /f ""%1"" /r /d y && icacls ""%1"" /grant administrators:F /t"
HKCR,"Directory\shell\runas\command","IsolatedCommand",,"cmd.exe /c takeown /f ""%1"" /r /d y && icacls ""%1"" /grant administrators:F /t"

; add advanced system properties to mycomp
HKCR,"CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\AdvSysProp",,0x00020000,"Advanced System Properties"
HKCR,"CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\AdvSysProp\command",,0x00020000,"control sysdm.cpl"

; add device manager to mycomp
HKCR,"CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\Devices",,0x00020000,"Device Manager"
HKCR,"CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\Devices","SuppressionPolicy",0x00010001,3c,00,00,40
HKCR,"CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\Devices\command",,0x00020000,"%windir%\system32\mmc.exe /s %SystemRoot%\system32\devmgmt.msc /s"

; add the mega-control panel on mycomp
HKCR,"CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\ExpCPL",,0x00020000,"Expanded Control Panel"
HKCR,"CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\ExpCPL\command",,0x00020000,"%windir%\explorer.exe shell:::{ED7BA470-8E54-465E-825C-99712043E01C}"
; unused alternate for the exact same thing
;HKLM,"SOFTWARE\Classes\CLSID\{20d04fe0-3aea-1069-a2d8-08002b30309d}\shell\Expanded Control Panel\command",,,"%windir%\explorer.exe shell:::{ED7BA470-8E54-465E-825C-99712043E01C}"

HKCR,"Folder\Shell\List Contents to text file\command",,,"%11%\cmd.exe /C DIR ""%1"" /B /O /S>""%1""""_contents list.txt"""

; contig
HKCU,"Software\Sysinternals\C","EulaAccepted",0x00010001,01,00,00,00
HKCR,"Directory\shell\contig","",0x00020000,"Defrag Folder with Contig"
HKCR,"Directory\shell\contig\command","",0x00020000,"%windir%\system32\contig.exe ""%L\*.*"" -v -s"

0

Share this post


Link to post
Share on other sites

to add command to context menu in cascade (whit sub menu) for windows 7 and windows 8 from reg file

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Folder\shell\my index]

"MUIVerb"="my index name"

"SubCommands"="my prog 1;my prog 2;|;comprimi in 7z"

"icon"="C:\\Program Files\\my prog\\prog.exe, 0"

"Position"=-

[HKEY_CLASSES_ROOT\*\shell\my index]

"MUIVerb"="my index name"

"SubCommands"="my prog 1;my prog 2;|;comprimi in 7z"

"icon"="C:\\Program Files\\my prog\\prog.exe, 0"

"Position"=-

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\my prog 1]

@=my prog 1"

"icon"="imageres.dll,109"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\my prog 1\command]

@="\"C:\\Program Files\\my prog\\prog.bat\" \"%1\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\my prog 2]

@="my prog 2"

"icon"="imageres.dll,109"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\my prog 2\command]

@="\"C:\\Program Files\\my prog 2\\my prog 2.exe\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\comprimi in 7z]

@="comprimi in 7z"

"Icon"="C:\\Progra~1\\7-Zip\\7zG.exe, 0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\comprimi in 7z\command]

@="\"C:\\Progra~1\\7-Zip\\7zg.exe\" a -t7z -mx=9 \"%1\".7z -oa \"%1\\*\""

;======================================

in context menu add 3 voice in cascade my index>(prog 1 prog2 comprimi in 7z) to max 20 voice in cascade menu

[HKEY_CLASSES_ROOT\Folder\shell\my index]============ all folder

[HKEY_CLASSES_ROOT\*\shell\my index]=============== all files

[HKEY_CLASSES_ROOT\DesktopBackground\Shell\my prog] === desktop

to wont use separator in voice use |

"SubCommands"="my prog 1;|;my prog 2;|;comprimi in 7z"

no separator in voice d'ont use |

"SubCommands"="my prog 1;my prog 2;comprimi in 7z"

position menu in context menu use botton top and midle

"Position"="Bottom"

"Position"="Top"

"Position"=-

Edited by odar
0

Share this post


Link to post
Share on other sites

I stumbled upon this post after trying to follow the instructions on Microsoft Support site - http://support.microsoft.com/kb/321379. The context menu was added upon running the reg file and I could even see the directory content in a notepad document for 2 seconds before it disappeared like a snapchat.

 

The alternate bat file code offered here by CharlotteTheHarlot worked well. Thanks much!

 

If someone can improve and save the txt file inside the same directory we are printing with this bat file, it will save future ‘where was this file saved to’ and it will not cause any problems of overwriting the same file when trying to print the content of multiple directories.

 

exit15

0

Share this post


Link to post
Share on other sites

If someone can improve and save the txt file inside the same directory we are printing with this bat file, it will save future ‘where was this file saved to’ and it will not cause any problems of overwriting the same file when trying to print the content of multiple directories.

You mean this one?

dir %1\*.* /ogn /-p > C:\Temp\Listing.txtnotepad.exe /p C:\Temp\Listing.txtcls

Try with:

@ECHO OFFDIR %1\*.* /ogn /-p > %1\Listing.txt notepad.exe /p %1\Listing.txt 

This should save the "Listing.txt" file to the same directory which was passed as a parameter to the batch, is this what you want? :unsure:

I would personally find more "correct" this version:

@ECHO OFFSETLOCAL ENABLEEXTENSIONSDIR "%~1\*.*" /ogn /-p > "%~1\Listing.txt"notepad.exe /p "%~1\Listing.txt"

but the result should be the same.

 

jaclaz

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

This one worked like a charm -- thanks (Fixing a small typo - ECHO OFF)

 

@ECHO OFFSETLOCAL ENABLEEXTENSIONSDIR "%~1\*.*" /ogn /-p > "%~1\Listing.txt"notepad.exe /p "%~1\Listing.txt"

exit15

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.