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. |
| |
|