SOME USEFUL BATCH FILES FOR WINDOWS
Adding directory contents options to a Windows Explorer right-click menu
Edmund J. Mullen
ed@edmullen.net
Alpharetta, GA
October 1999, October 2002

BACKGROUND

Windows drives me crazy by not letting me do things I’ve been doing for 20+ years with computers.  (I’m a throwback, I know.)  Like getting a complete listing of all the files and statistics in a directory (sorry!  “folder”) or even on an entire drive.  I find this very useful for a variety of reasons all, I am told, resulting from the compulsive nature of my personality.  I really do wanna know this stuff!

Sometimes it’s nice to know what’s out there on my hard drive(s).  I like to know, for instance, how big the whole project I’m working on is getting.  I might want to track how much space files of a certain type are occupying.  I might want to take a directory listing and import it into Excel to run totals on various subsets of a project.  Maybe even to project how big a project will get if I do certain things.  Or what the average size is of, say, all the MP3 files on my system.  Not easily done with Explorer.  Oh, sure, I could guess.  Or even look in Windows Explorer and add up a bunch of file sizes and figure the average on a calculator.  Which was what I was doing when I said, “Hello?  This is a computer, right? Why the heck am I doing this by hand???  Hey, Bill Gates!  It’s a computer.  Stop worrying about goofy, moronic, paperclip helpers that don’t know anything and gimme some software that will let this PC do what it’s really good at - adding and subtracting.”  I rant, therefore I am.

In October 1998 I read a column in PC Computing magazine and thought I’d found Nirvana.  There on page 171 was a description of a batch file process you can use in Windows 98 that lets you right click on a directory (dang!  sorry, “folder”) and print or view a DOS-type directory listing of the contents of that folder.  Over time I’ve used this a great deal.  And, of course, found a few tweaks to make it even more to my liking and feed my penchant for compulsive behavior.  

Some things you can do with this:

·	Save a directory listing to a text file
·	Change the batch files that create the listings to customize the appearance of the listings
·	Import the text files into Word for pretty formatting and printing
·	Import the text files into Excel to perform formatting and calculations such as finding the average file size in a directory/folder
·	Use Excel to calculate directory sizes if certain files are removed

Now, this is not a utility.  It is a set of batch files that produce the listings, a method for integrating them into your Explorer context menus (right-click), and a suggestion for putting access to the files on your Start Menu in Windows.  You should be able to accomplish all of this without resorting to editing the System Registry.  However, if you know what you're doing you can accomplish the same thing via that method of "installation."

So, for what it’s worth, here it is.

*********************************************************
!!! ALERT !!! CRITICAL UPDATE FOR WINDOWS XP USERS!!!
Ok, ok.  Calm down, it's not that dire.  However, on October 1, 2004 I discovered a Windows XP problem that may occur if you apply this tweak.  So before you go any further read the file: XP ISSUES WITH DIRLIST.txt
*********************************************************

OVERVIEW
I have a folder, “G:\Utilities\”, on my systems.  That’s where I keep these batch files and also store the directory listing files when they are created.  You can change the path and filename for the location where the files will be stored to something you like on your system. Just be aware of what you are doing and be consistent.  And make sure the path actually exists.

I assume that you, like I, in most cases want to not only capture the contents of the folder you click on but also its sub-folders.  If that’s not the case you can edit the appropriate batch files and remove the “/s” switch in the DIR command.

I originally developed this system for use with Windows 98 and Windows 98SE.  I’ve tested these files in that environment, and in Windows XP Home Edition, although I suspect it will also work with Windows 95 and Windows 2000.  Windows XP will have slight cosmetic (GUI) differences from some of the notes in this documentation.

I’ve tested this on 233 MHz machines with 64 Mb of RAM and hard drives of  6 and an 8 GB.  I have also implemented this on a 933 MHz system with 512 Mb of RAM using 42 and 80 MB drives.

Some directory listings can be very large.  If you do a “ROOT and SUBS” listing on a large drive the resulting listing file can easily result in a huge text file.

When you open a listing file, if it is too big to fit into Notepad’s file size limit, then Windows will (should) ask you if you want to use Wordpad instead.  That’s ok, just do it.  Or, you can edit the batch file(s) to use a different text editor by default.  Just make sure you specify the full path or Windows might not find the program.

And, yes, I know my file names are a bit loony.  So am I.  Change ‘em if you don’t like ‘em.  Just be consistent across the system.

I did not put the /s subdirectory switch into the batch file that prints a listing.  God forbid I should mis-click or just forget and start sending the entire structure of my hard drive to the printer.  I figure you wouldn’t be too thrilled about that either.  You can, if you are a real glutton for punishment, edit the batch file(s) to add the /s switch.  Do NOT email me if you do this.  I will have no sympathy.  I may even have to take away your PC privileges for a week until we’re sure it’s safe for you to operate it on your own without hurting yourself.  By the way.  Think first before running any of these on a CD-ROM or network drive.

I think I’ve got all this correct.  If I messed it up somehow let me know.

HOW TO
Here’s how to get it done.

The first thing is to have the batch files on your system.  You can create the batch files by typing them yourself.  Or, cimply create them by copying and pasting the examples below.  Store them in a folder (on my system it's the “G:\Utilities\” folder).  If you don’t have a folder of this name, create one in the root of your primary hard drive (usually drive C:\) or some other drive.  If you have no idea what I'm talking about, please stop now and delete this file!

You can also do all of what follows via hacking the registry.  Don't ask me how to do this.  Don't even contemplate it unless you know what you're doing.  It's a bad thing unless you're prepared to reformat all of your hard drives and re-install Windows from scratch in the event of a disaster.  Ok?

The relevant batch files are:

G:\Utilities\DirlistBARE.bat
G:\Utilities\DirlistNEW.bat
G:\Utilities\DirlistPRINT.bat
G:\Utilities\DirlistROOT.bat
G:\Utilities\DirlistROOTandSUBS.bat
G:\Utilities\DirlistROOTandSUBSAppend.bat
G:\Utilities\DirlistROOTAppend.bat
G:\Utilities\DirlistVIEW.bat
G:\Utilities\DirlistWIDE.bat

When run, the batch files will create these plain text files containing the directory listings:

G:\Utilities\BARE.dirlistingfile
G:\Utilities\NEW.dirlistingfile
G:\Utilities\ROOT.dirlistingfile
G:\Utilities\ROOTandSUBS.dirlistingfile
G:\Utilities\VIEW.dirlistingfile
G:\Utilities\WIDE.dirlistingfile

Next, you have to add the batch files to the right-click menus in Windows Explorer.

To handle the folders below the root folder of a drive:
1.  Open Windows Explorer
2.  Choose VIEW, OPTIONS (or FOLDER OPTIONS)
3.  Click the FILE TYPES tab
4.  Scroll through the list and select FILE FOLDER
5.  CLICK on EDIT and then NEW (in Windows XP click ADVANCED then NEW)
6.  In the NEW ACTION dialog box, in the “Action” fill-in enter “Dir listing NEW” or another appropriate description.
7.  In the “Application Used to Perform Action” fill-in box enter the path and name of the appropriate batch file (such as “G:\Utilities\DirlistNEW.bat”)
8.  Click OK
9.  Click Close
10.  Click Close
11.  Repeat for each of the operations represented by each batch file you want to implement.  Name them appropriately.

To handle the root folder of a drive:
1.  Open Windows Explorer
2.  Choose VIEW, OPTIONS (or FOLDER OPTIONS)
3.  Click the FILE TYPES tab
4.  Scroll through the list and select FOLDER.  Do NOT select FILE FOLDER
5.  Click on EDIT and then NEW (in Windows XP click ADVANCED then NEW)
6.  In the NEW ACTION dialog box, in the “Action” fill-in enter “DIR listing ROOT” or “DIR listing ROOT and SUBS”.
7.  In the “Application Used to Perform Action” fill-in enter the path and name of the appropriate batch file (such as “G:\Utilities\DirlistROOT.bat”)
8.  Click OK
9.  Click Close
10.  Click Close
11.  Repeat for each of the operations represented by each batch file you want to implement.  Name them appropriately.

USING THE BATCH FILES
1.  Open Windows Explorer
2.  Right click any folder
3.  A pop-up menu appears.  Your new options based on the batch files should be there.  (The two for the ROOT operations may appear apart from the others.  That’s because they’re associated with the FOLDER options and the others are associated with the FILE FOLDER options.  Also, you may other FOLDER options on your system that are not on mine.).  Click on, for instance, DIR listing NEW.

You’ll see a blank DOS window either flash by (if it’s a small folder) or sit there on the screen for awhile.  Be patient.  If you did this on a very large folder with lots of files and sub-folders (like “C:\Windows” or just "C:\" - YIKES!) the DOS window will be up there apparently doing nothing for quite awhile depending on the size and speed of your system and other magical things.  The directory listing will be saved in the appropriate “.dirlistingfile” in the “G:\Utilities\” folder.

If you selected the batch file process VIEW, then you’ll see the DOS window flash (or stick around awhile) and then Notepad will open and the directory listing will be there to work with.  You can just view it and shut down Notepad.  Or, you can print it or select all or some of it to copy and paste into another application.  The listing is saved in “Directory Listing VIEW.dirlistingfile” in the “G:\Utilities\” folder so you can open it with any text editor later.

Try right clicking on the root folder, for instance, “C:\”.  Your right-click options that are associated with FOLDER will be there but not the ones for FILE FOLDER.  Click on “DIR listing for ROOT” or “DIR listing for ROOT and SUBDIRS”.

ANOTHER WRINKLE
Assuming you haven’t edited them and are using them as supplied, then after you run these batch files (by right-clicking on a folder and executing the commands in Explorer) you will have the following files:

	G:\Utilities\BARE.dirlistingfile
	G:\Utilities\NEW.dirlistingfile
	G:\Utilities\ROOT.dirlistingfile
	G:\Utilities\ROOTandSUBS.dirlistingfile
	G:\Utilities\WIDE.dirlistingfile

You can always open them with Notepad, Wordpad, or your favorite text editor (assuming they are not too big for the particular program).  What I did was create desktop icons for each of them and associate the filetype “dirlistingfile” with Wordpad.  I even put shortcuts to them on my Start menu so I can get at them easily without minimizing everything that’s running to get to the desktop icons.  Here’s how.

After you’ve run each of the batch files (just do it on some small folder for the sake of creating the text files), open Explorer and click on the “G:\Utilities\” folder.  Then, with both Explorer and a blank area on your desktop visible, in Explorer find the text file for which you want to create a desktop icon.  Right click and hold and drag the file onto the desktop.  Windows will ask if you want to move it, copy it, create a shortcut, or cancel the operation.  Choose “Create Shortcut(s) Here.”  A shortcut will appear on your desktop.  You can also highlight all the files, right-click, choose Send to - Desktop (create shortcuts).  And you can just drag them to your Start menu so they'll always be handy.

Next, double click on the shortcut on your desktop that you just created.  Windows will bring up the “Open With” dialogue since it has no idea what a "dirlisting" file type is nor what to do with it.  Under “Choose the program you want to use” scroll down and select an editor of your choice.  Select the check box that says to “always use this program to open this file”.  If you stuck with my wacky file names this will work and it’s highly unlikely that any other program will usurp this file type in the future.  See, there was a method to my madness.

Go be compulsive!

Ed Mullen
Alpharetta, GA
October 2002
ed@edmullen.net

=================================

BATCH FILES

=================================

@echo off
Rem DirlistBARE.bat

Rem Original concept from PC Computing, October 1998, page 171
Rem Modified by Ed Mullen, October 1998, October 1999, October 2002
Rem Email: ed@edmullen.net

Rem 	 Issue the DIR command
Rem	 with a system variable set to the folder
Rem    that was right-clicked
Rem    and the 'no page pause' switch
Rem    and the 'sort' switch
Rem    grouping directories and sorting by
Rem    extension, name, date, size
Rem    and the 'sub-directory' switch
Rem    and redirecting output from the screen to a dirlisting file
Rem    in the 'temp' directory (or other place you specify)
Rem    THIS COMMAND OVERWRITES (or creates) THE FILE

Rem Execute the command

	Dir %1 /-p /b /o:gends /s > "G:\Utilities\BARE.dirlistingfile"

EXIT

=================================

@echo off
Rem DirlistNEW.bat

Rem Original concept from PC Computing, October 1998, page 171
Rem Modified by Ed Mullen, October 1998, October 1999, October 2002
Rem Email: ed@edmullen.net

Rem 	 Issue the DIR command
Rem	 with a system variable set to the folder
Rem    that was right-clicked
Rem    and the 'no page pause' switch
Rem    and the 'sort' switch
Rem    grouping directories and sorting by
Rem    extension, name, date, size
Rem    and the 'sub-directory' switch
Rem    and redirecting output from the screen to a dirlisting file
Rem    in the 'temp' directory (or other place you specify)
Rem    THIS COMMAND OVERWRITES (or creates) THE FILE

Rem Execute the command

	Dir %1 /-p /o:gends /s > "G:\Utilities\NEW.dirlistingfile"

EXIT

=================================

@echo off
Rem Dirlist PRINT.BAT

Rem Original concept from PC Computing, October 1998, page 171
Rem Modified by Ed Mullen, 11/16/98, 10/16/99
Rem Email: ejmullen@compuserve.com

	Dir %1 /-p /o:gne /s > "%temp%\Dir Listing"

Rem The following command starts notepad
Rem    with the 'w' switch which holds batch file execution until
Rem    notepad is finished doing its thing
Rem    then opens the just created file
Rem    and sends it from Notepad to the printer
Rem    with the /p switch

	Start /w notepad /p "%temp%\Dir Listing"

Rem this one deletes the temporary file

	Del "%temp%\Dir Listing"

EXIT

=================================

@echo off
rem DirlistROOT.bat

Rem Original concept from PC Computing, October 1998, page 171
Rem Modified by Ed Mullen, October 1998, October 1999, October 2002
Rem Email: ed@edmullen.net

Rem 	 Issue the DIR command
Rem	 with a system variable set to the folder
Rem    that was right-clicked
Rem    and the 'no page pause' switch
Rem    and the 'sort' switch
Rem    grouping directories and sorting by
Rem    extension, name, date, size
Rem    and the 'sub-directory' switch
Rem    and redirecting output from the screen to a dirlisting file
Rem    in the 'temp' directory (or other place you specify)
Rem    THIS COMMAND OVERWRITES (or creates) THE FILE

Rem Execute the command

	Dir /-p /o:gends > "G:\Utilities\ROOT.dirlistingfile"

EXIT

=================================

@echo off
rem DirlistROOTandSUBS.bat

Rem Original concept from PC Computing, October 1998, page 171
Rem Modified by Ed Mullen, October 1998, October 1999, October 2002
Rem Email: ed@edmullen.net

Rem 	 Issue the DIR command
Rem	 with a system variable set to the folder
Rem    that was right-clicked
Rem    and the 'no page pause' switch
Rem    and the 'sort' switch
Rem    grouping directories and sorting by
Rem    extension, name, date, size
Rem    and the 'sub-directory' switch
Rem    and redirecting output from the screen to a dirlisting file
Rem    in the 'temp' directory (or other place you specify)
Rem    THIS COMMAND OVERWRITES (or creates) THE FILE

Rem Execute the command

	Dir /-p /o:gends /s > "G:\Utilities\ROOTandSUBS.dirlistingfile"

EXIT

=================================

@echo off
rem DirlistROOTandSUBSAppend.bat

Rem Original concept from PC Computing, October 1998, page 171
Rem Modified by Ed Mullen, October 1998, October 1999, October 2002
Rem Email: ed@edmullen.net

Rem 	 Issue the DIR command
Rem	 with a system variable set to the folder
Rem    that was right-clicked
Rem    and the 'no page pause' switch
Rem    and the 'sort' switch
Rem    grouping directories and sorting by
Rem    extension, name, date, size
Rem    and the 'sub-directory' switch
Rem    and redirecting output from the screen to a dirlisting file
Rem    in the 'temp' directory (or other place you specify)
Rem    THIS COMMAND APPENDS TO THE EXISTING FILE

Rem Execute the command

	Dir /-p /s /o:gends >> "G:\Utilities\ROOTandSUBS.dirlistingfile"

EXIT

=================================

@echo off
rem DirlistROOTAppend.bat

Rem Original concept from PC Computing, October 1998, page 171
Rem Modified by Ed Mullen, October 1998, October 1999, October 2002
Rem Email: ed@edmullen.net

Rem 	 Issue the DIR command
Rem	 with a system variable set to the folder
Rem    that was right-clicked
Rem    and the 'no page pause' switch
Rem    and the 'sort' switch
Rem    grouping directories and sorting by
Rem    extension, name, date, size
Rem    and the 'sub-directory' switch
Rem    and redirecting output from the screen to a dirlisting file
Rem    in the 'temp' directory (or other place you specify)
Rem    THIS COMMAND APPENDS TO THE EXISTING FILE

Rem execute the command

	Dir /-p /o:gends >> "G:\Utilities\ROOT.dirlistingfile"

EXIT

=================================

@echo off
Rem DirlistVIEW.bat

Rem Original concept from PC Computing, October 1998, page 171
Rem Modified by Ed Mullen, October 1998, October 1999, October 2002
Rem Email: ed@edmullen.net

Rem 	 Issue the DIR command
Rem	 with a system variable set to the folder
Rem    that was right-clicked
Rem    and the 'no page pause' switch
Rem    and the 'sort' switch
Rem    grouping directories and sorting by name then extension
Rem    and the 'sub-directory' switch
Rem    and redirecting output from the screen to a dirlisting file
Rem    in the 'temp' directory (or other place you specify)
Rem
Rem    THEN, automatically open the file in Notepad

	Dir %1 /-p /o:gends /s > "G:\Utilities\VIEW.dirlistingfile"

	Start notepad "G:\Utilities\VIEW.dirlistingfile"

EXIT

=================================

@echo off
Rem DirlistWIDE.bat

Rem Original concept from PC Computing, October 1998, page 171
Rem Modified by Ed Mullen, October 1998, October 1999, October 2002
Rem Email: ed@edmullen.net

Rem 	 Issue the DIR command
Rem	 with a system variable set to the folder
Rem    that was right-clicked
Rem    and the 'no page pause' switch
Rem    and the 'sort' switch
Rem    grouping directories and sorting by name then extension
Rem    and the 'sub-directory' switch
Rem    and redirecting output from the screen to a dirlisting file
Rem    in the 'temp' directory (or other place you specify)

	Dir %1 /-p /o:gends /s /w "G:\Utilities\WIDE.dirlistingfile"

EXIT