TEG Logo 
Custom Search
 
TEG Home    |     Win XP Main     |     Win Vista Main     |     Win 7 Main     |     Win 8 Main     |     Forum     |     Commentary     |     Links     |     Advertise     |     Contact TEG
Subscribe to The Elder Geek Content Update Notification          |||           The Elder Geek Windows Forums Are Open for Posting !
Windows 7 Index  >>>  A  |  B  |  C  |  D  |  E  |  F  |  G  |  H  |  I  |  J  |  K  |  L  |  M  |  N  |  O  |  P  |  Q  |  R  |  S  |  T  |  U  |  V  |  W  |  X  |  Y  |  Z  <<<  Windows 7 Index
 
Windows 7
 
Install/Remove
Clean Install - No Operating System Inst.
Clean Install - Windows XP Installed
Upgrade Install - Windows XP Installed
Clean Install - Windows Vista Installed
Upgrade Install - Windows Vista Installed
Clean Install to VMware Virtual Machine
Another XP to Win7 Upgrade Article
Slipstream / Image
Create Bootable Image - Win 7 w/SP1
Slipstream SP1 w/One Computer
Slipstream SP1 w/Two Computers
This was known as slipstreaming in XP.
Virtual Machine Installations
Clean Install to VMware Virtual Machine
System
Create A Bootable Windows 7 USB Key
Create Multiple Version Win 7 Install DVD
Hidden Files and Folders - Make Visible
Set BIOS to Boot from CD/DVD Drive
System File Checker (SFC) Tool
Backup - Restore - Recovery
Backup - Restore - Recovery in Windows 7
Backup and Restore - Initial Setup
Backup and Restore - Change Settings
Backup and Restore - Scheduling
Backup and Restore - Managing Disk Space
Create A System Image of Windows 7
Create A Windows 7 System Repair Disk
Recover System Using System Image Backup
Restore System from Data File Backup
 
User Interface
Shortcut - How to Create
Shortcut - Remove Arrow Overlay
Shortcut - Backup and Restore
Shortcut - Shutdown Computer
Shortcut - Shutdown Computer - Timed
Shortcut - Shutdown Computer - Cancel
Registry
Backup and Restore Win 7 Registry
Registry Edits for Windows 7
 
Microsoft Resources
Windows 7 Home
Windows Client TechCenter
Windows 7 System Requirements
Windows 7 Downloads
Windows 7 - Discover and Explore
Windows 7 - Pilot and Deploy
Windows 7 - Manage Windows 7
Windows 7 - The Windows Blog
Has The Elder Geek
site been useful?
 Consider A Donation
 
TEG is hosted by:
Hosting Matters
 
Logitech Mice 
 
 
Recommended: Click here to run a FREE system scan


Generate a Directory and File Listing from a Windows 7 Explorer Context Menu

I find it amazing that after XP, Vista, and now Windows 7, Microsoft still hasn't included the ability to generate a file and directory listing of Windows Explorer as an editable text file or printable hardcopy as a standard feature of the operating system. Here's how to create a context menu item that when clicked will generate a directory and file list. The batch file is configurable to send the output directly to a printer, to the desktop as an editable text file, or to applications like Microsoft One Note for editing and printing.
 
Step One - Create A Batch File
The first step is to create a batch (.bat) file. This file will be used in combination with some registry entries to make the whole process work. The format for the .bat file is:
 
@echo off
dir %1 /-p /o:gen > "%temp%\Directory List"
start /w notepad /p "%temp%\Directory List"
del "%temp%\Directory List"
exit
 
Use Notepad to create the file. If you want to, just copy and paste the five lines above into Notepad. For those purists that will write saying some stuff can be eliminated from the batch file to make it more efficient while other things can be added to make it jump through hoops, yes, you're right. There's a lot of latitude available when it comes to batch files, so if you have some suggestions, feel free to send them along and I'll share them with others at the end of this tutorial.

So you're clear, the name 'Directory List' in the code references the Notepad file that will be created and opened when the context menu item is clicked. The name can be whatever you'd prefer it be called. In the example below it's Directory List, but it could just as easily be List of Files, Named Files, or even Wally if you have a sense of the bizarre.
 

After the file is created in Notepad it needs to be saved with a .bat extension. If you just click [File] and [Save] in the Notepad menu bar the file will be saved as a text file and that won't work. Instead, click [File] and then [Save As...] to open the window shown below. Some things to keep in mind are;

  • You need to enter a name for the file in the [File Name: ] field - and - it needs to have the .bat extension, not .txt extension. Again, it doesn't matter what file name you assign here, but make it something that is relevant to what the .bat file is designed to accomplish.
  • In order to be able to use the .bat extension you need to access the [Save As Type] menu via the drop down menu arrow and select the [ All Files (*.*) ] option.
  • Make sure the [ Encoding: ] section displays the ANSI option.
  • Finally, you need to select where the .bat file will be saved. The location where it needs to be is in C:\Windows, but more than likely system permissions will deny you access to save in C:\Windows. Windows 7 is picky about these things. Rather than go through the nonsense of changing permissions, just save the file to the Desktop as I did below. Click the [ Save ] button. After it's saved to the Desktop just copy it to its final C:\Windows location.
 
Step Two - Modify the Context Menu
Back in the days of XP there was a nifty little tab called 'File Types' that contained a 'New Action' applet that made this part of the process a snap. For some reason it has disappeared in Windows 7 (and probably Vista too, though I never bothered to look) so now you have to either manually edit the registry or create a .reg file to accomplish this task. This is progress? Ah well, no big deal, we'll just do it manually first and then show you how to create a .reg file afterward if that's your preference.
1 - To get started, go to Start and in the Search Programs area at lower left, type in [ regedit ] and press enter to open the Registry Editor. Most likely you'll have to answer [Yes] to the User Account Control (UAC) prompt.
2 - With Registry Editor open, scroll down in the left pane until you come to the HKEY_CLASSES_ROOT\Directory\shell key. You'll have to expand some directories using the arrows and there is a viewer at lower left to help you keep track of what key is being currently displayed.
3 - Right click Shell > New > Key
4 - The new key has been created.
5 - Right click on the name of the new key created above, click Rename and type in a name for the new key. Once again, the name doesn't matter, but making it something relevant to the task this key will control seems sensible.
6 - In the left pane of registry editor, make sure the key that was created and renamed is highlighted. In the right pane, there is a 'string' visible called (Default) with (value not set) in the data column. Double click on the string to open the Edit String dialog box. Leave the [ Value Name: ] area set to (Default) and in the [ Value Data: ] area type in the name you want to actually appear on the context menu in Windows Explorer. Yet again, there is no right or wrong thing to use - but make it something relevant to what task will be carried out when the selection is clicked. Click [OK] button to proceed.
7 - if you want to check your work to this point, open Windows Explorer and right click on a directory. Whatever name you entered in the previous step for the string value should now be visible in the context menu. It isn't functional yet, but it's there.
8 - Next up is creating the internal workings that make this whole exercise function. For that we need a new key and another 'string' value under the Directory List key created earlier. The procedure is exactly the same as Steps 4 and 5 above, except you start by right clicking on the Directory List key so the new key is created beneath it as a sub-key. Rename the new key to 'command' -- and this time, the name does make a difference. You want to end up with exactly what is shown below; the command folder in the left pane and the string value in the right pane.
9 - With the 'command' key highlighted in the left pane, double click the string value at the top of the right pane to open the Edit String dialog box. Leave the [ Value Name: ] set to (Default) and change the [ Value Data: ] setting as shown below, substituting the correct name of the .bat file you created earlier, leaving the "%1" appended to the end of the command. Click [OK] button to continue.
10 - Close Registry Editor to complete the procedure.
 
Alternate Method: Create A Registration (.reg) File for Registry Changes
I understand some users may be hesitant to actually edit the registry. If that's the case, you can create a file with a .reg extension that when double clicked will make all the registry changes for you without having to physically open and edit the registry. I'm 'not' going to offer the .reg file for download like many sites. Instead, I'll show you how to make one. Then, if you do download one later, you'll have the knowledge to open and inspect it to gain an understanding of what it really does in the background, not just take someone's word for it being safe or non-malicious.
1 - Open Notepad and either copy and paste the text below or type it in exactly as shown. This .reg file is made to work with this tutorial, so if you've made any changes to the batch file name or want different key names in the registry you'll have to modify the code.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Shell]
@="none"

[HKEY_CLASSES_ROOT\Directory\Shell\Directory List]
@="Generate Directory List"

[HKEY_CLASSES_ROOT\Directory\shell\Directory List\command]
@="Printdir.bat \"%1\""

2 - The items identified below with red arrows refer to keys in the registry that either already exist or that will be created when the .reg file is run. The items identified by green arrows are string values that will be created for the referenced key. For example, in the second entry below, this one entry comprises Steps 3-6 in the instructions above, creating the Directory List key and then setting the string value to "Generate Directory List" which is the actual wording that will appear in the context menu.
3 - On the Notepad menu bar click File > Save As... and refer to the screen capture below. Give the file a name and use the .reg extension. Use the drop down list to change [ Save As Type: ] to All Files. Make sure encoding remains ANSI. Where the file is saved doesn't matter, just as long as you know where it's saved. I saved it to the desktop.
4 - That's it for creating a Registration (.reg) file. To use it, just double click the file and click through two prompts that confirm you understand changes will be made to the registry and you really want to make those changes. This one file takes the place of everything you'd do in steps 1 thru 10 of Step Two above.
 
Step Three - Using the File List Generator
That's it !  Congratulations. You've created a new item on the context menu that's ready to go to work. So now that it's there, what can you do with it? Open up Windows Explorer, right click the directory to be used as the root of the directory and file list and then click [ Generate Directory List ], or whatever you named your version, on the context menu.
What actually happens after you click [ Generate Directory List ] on the context menu? If you followed the tutorial above exactly as it's laid out, what happens next depends on what you have selected in the Devices and Printers folder as the default printer. In the example below the default printer is the HP Color LaserJet 2550 PCL5 so the directory list will be sent there, but you could just as easily set any of the other devices as the default and the output would be directed to that selection.

I very seldom leave an actual paper and ink printer as the default device for two reasons; first, I'm a tree hugger and environmentalist and hate wasting trees and paper, and secondly, applications like OneNote or SnagIt 9 are far more versatile and useful than a hard copy. If a printout is absolutely required it can be generated through the auxiliary programs print function after being edited.
 
One last tweak and we'll call it a day. Suppose you don't have any of the items listed in Devices and Printers shown above; no printer, no applications like OneNote, SnagIt, XPS Document Writer, or no fax machine to receive the output of the batch file? If that's the case, you'll see the two screens shown below. The first asks if you want to install a printer. If you decline, the second screen appears saying a printer can't be accessed followed by closing all the open windows.

[Click to Enlarge]

[Click to Enlarge]
This leaves you unable to generate a directory and file list and have it appear on the desktop where it can be saved as a text file. If you find yourself in this situation all is not lost. All that's required is a modification to the batch file created back in Step One.
 
The original batch file is shown below. The part to be modified is highlighted in red. It consists of three items; a <space>, a </>, and a <p>.
All you need to do is delete those three items to complete the modification.
This is the end result of the modified batch file. Nothing else has changed in the file.
Make sure it's saved with the .bat extension.
This file will replace the .bat file that's currently in C:\Windows created in Step One.
@echo off
dir %1 /-p /o:gen > "%temp%\Directory List"
start /w notepad /p "%temp%\Directory List"
del "%temp%\Directory List"
exit
@echo off
dir %1 /-p /o:gen > "%temp%\Directory List"
start /w notepad "%temp%\Directory List"
del "%temp%\Directory List"
exit
Similar to when the original batch file was created, depending on permissions, you may or may not be able to save it directly to C:\Windows. If access is denied, just save it to the desktop as Printdir with the .bat extension and then copy it into C:\Windows, overwriting the file already present when prompted. No other changes to the batch file, and no changes to the registry are required.
 
Once the change has been implemented, go back to Windows Explorer, right click the directory to be used as the root of the directory and file list and then click [ Generate Directory List ], or whatever you named your version, on the context menu. Now, instead of the batch file looking for a printer or returning an error because no printer enabled application is available, a Notepad text file will be opened on the desktop. Just like any text file it can be edited, renamed, and then saved to the location of your choice using the File > Save As command on the Notepad menu bar.
Of  course you always have the option of going back and editing the batch file again if circumstances change and you want to point the output to a printer or application listed in Devices and Printers in Control Panel.
 



XP Main Page


Vista Main Page


Win 8 Main Page

Be sure to visit TEG on
Windows XP and Vista

Download VMware Workstation 7.1 Today! 
Trend Micro Titanium Internet Security 
 
 
System Services Guide
for Windows 7
 
Testing Operating Systems On A Primary System

Here's a method I use for testing operating systems and other software on a primary system without impacting the current primary operating system.
Roxio Creator  2012 Pro 
 
System Mechanic&reg; - Fix and Speed Up Your PC... 
Set BIOS to Boot from CD/DVD Drive

For those who aren't familiar with the steps involved, here's a generic guide to the procedures.
 
Has The Elder Geek
site been useful?
 Consider A Donation
 
No Drive or Partition Available in VMware XP to Win 7 Install

This tutorial explains how to correct the issue and allow the Windows 7 installation to proceed.
UK - avast! Logo, homepage 
 
 
 
Custom Search
 
   
 
-  Important Information  -
The Elder Geek sites contain many articles and suggestions for modifying the Windows operating system. I've tried these tweaks and tips on many systems. Sometimes they work, sometimes not. The point is, ensure you have a current, tested backup of all system and data files and understand how to restore the system in case something goes very wrong. You can still yell at me, but I assume no responsibility for your actions and use of the information and disclaim any legal responsibility for any consequences of such actions.
 
     
  Copyright © 2002/2003/2004/2005/2006/2007/2008/2009/2010/2011, Jim Foley/The Elder Geek, All Rights Reserved Worldwide
 Reproduction, in any form, of information on this site is prohibited without express written permission.
 Microsoft is in no way affiliated with, nor offers endorsement of, this site.