If you’ve spent much time working in a DOS-based environment, chances are that you’re very familiar with the Dir command. When used in its most basic form, the Dir command simply displays a list of all the files and subdirectories contained within a particular directory. However, the Dir command has access to a fleet of special command line parameters that allow it to perform a host of very specific file listing and sorting operations. While you can perform many of these operations in Windows Explorer, the speed and accuracy with which you can perform them with the Dir command is astounding. Furthermore, you can easily combine these command line parameters to create unique directory listings on the fly.
Unfortunately, shelling out to a command prompt and typing the Dir command with its parameters can be a tedious task. Wouldn’t it have been nice if Microsoft had given the Dir command a graphical user-interface so that you could easily access its power from within Windows?
I’ve always thought so. Recently, I hunkered down and created an HTML application (HTA) called the Dir Commander, which uses features from both Windows Script Host and VBScript to make it possible to configure and launch the Dir command from within the Windows user interface. And, best of all, the Dir Commander works in the most current versions of the Windows operating system—Windows 98/Me and Windows 2000/XP.
Download Dir Commander
You can download Greg Shultz's Dir Commander application by following this link or clicking on the Downloads link in the navigation bar on the left of this page. TechProGuild and TechRepublic have many useful documents, templates, and applications available for download, so be sure to check out our other offerings.
Installing the Dir Commander
Once you download the DirCommander.zip archive file, manually installing the application on your hard disk is easy. To do so, create a folder in the root directory of drive C called DirCommander. (Keep in mind that the script is specifically designed to run from a folder named DirCommander. If you name the folder something other than DirCommander, the script won’t work correctly.)
Then, unzip the Dir Commander.zip archive file and copy these four files to the DirCommander folder:
The DirCom.ico file provides the DirCommander with the icon that it uses for the control menu and the taskbar. The DirComHelp.hta file is a simple Help file that explains how the options in the Dir Commander dialog box correspond to the actual Dir command’s parameters. The DirCommander.bat file is a standard DOS-based batch file that simply launches the HTA. The DirCommander.hta file is of course the main HTML application.
Why use a batch file?
Here is why the batch file was necessary for integrating the HTA into the Windows operating system: You’ll notice that the Files-of-type list box specifies Programs as the default file type. This is because the Windows operating system will only accept what it considers to be executable files for the Application Used To Perform Action text box. In this case, that means files with an .exe, .com, .pif, or a .bat extension—it won’t accept files with an .hta extension. So, I need to use a batch file to link the script to the operating system.
Integrating the HTA into the operating system
To make it easy to use the Dir Commander, I decided to integrate the HTA into the operating system so that to view the files in any particular folder, you just right click on that folder in Windows Explorer and select Dir Commander from the context menu. While integrating the HTA into the operating system may sound difficult, it’s actually a pretty simple operation. However, since there are a number of steps in the procedure, it is essential that you follow the instructions closely. Also, as I work through the procedure I’ll use Windows XP as the example system for the screen shots; the procedure is almost identical in the other Windows operating systems. If there are any differences, I’ll point them out as I go along, otherwise you can assume the steps are the same for all operating systems.
To get started, you’ll launch Windows Explorer, pull down the Tools menu, and select the Folder Options command. (In Windows 98, you’ll find the Folder Options command on the View menu.) When you see the Folder Options dialog box, select the File Types tab. Now, scroll through the Registered file types list and select Folder Options, as shown in Figure A, then click the Advanced button. (In Windows 98, you’ll click the Edit button.)
|Locate and select the Folder type in the Registered file types list box.|
When you do, the Edit File Type dialog box will open, as shown in Figure B. (The Windows 98 Edit File Type dialog box is slightly larger, but the controls you’ll use are identical.)
|The Edit File Type dialog box is designed to allow you to assign commands to the Folder type.|
To continue, click the New button and you’ll see the New Action dialog box, shown in Figure C. Now, type Dir Commander in the Action text box. This will become the command that appears on the context menu.
|You’ll use the New Action dialog box to actually integrate the script with the operating system.|
Now, click the Browse button adjacent to the Application Used To Perform Action text box and use the Open With dialog box to locate and select the DirCommander.bat file, which will be in the C:\DirCommander folder, as shown in Figure D. To continue, click OK. (If you’re using Windows 98 or Windows Me, you should read the next section, “Configuring the batch file In Windows 98/Me,” before you perform this step.)
|You'll use the Open With dialog box to locate and select the batch file.|
At this point, your New Action dialog box will look like the one shown in Figure E. You can then click OK.
|Your New Action dialog box should now look like this one.|
When you return to the Edit File Type dialog box, you'll see that the Dir Commander command now appears in the Actions list box, as shown in Figure F.
|The new Dir Commander command now appears in the Actions list box.|
To complete the procedure, click OK to close the Edit File Type dialog box and then click Close to close the Folder Options dialog box. (In Windows 98, you’ll click the Close button twice—once to close the Edit File Type dialog box and once to close the Folder Options dialog box.)
Configuring the batch file in Windows 98/Me
In Windows XP, the Command Prompt window will automatically close as soon as the batch file has run. However, in Windows 98/Me, the MS-DOS Prompt window will remain open.
If you want the MS-DOS Prompt window to automatically close when the batch file has run, you’ll need to make a few adjustments. To begin, open Windows Explorer and locate the DirCommander.bat file. When you do, right-click the file and select the Properties command from the context menu. When the DirCommander.bat Properties sheet appears, click the Program tab, select the Minimized option in the Run dropdown list, and select the Close On Exit check box. When your DirCommander.bat Properties sheet looks like the one shown in Figure G, click OK to close it.
|You configure the batch file so that it runs in a minimized window that closes when the file has finished running.|
As soon as you click OK, you'll notice that Windows 98/Me automatically creates a shortcut to the DirCommander.bat file. You then need to associate this shortcut with the Folder type rather than the batch file itself.
To do so, you’ll add the shortcut, which will be called DirCommander.pif, to the Application Used To Perform Action text box in the New Action dialog box. In this case, the New Action dialog box will look like the one in Figure H. When you add the shortcut to the New Action dialog box, you’ll see that its extension is .pif.
|Here is what the New Action dialog box will look like.|
Using the Dir Commander
Now that you've created the command to launch the Dir Commander, using it is easy. However, keep in mind that you must launch it from the Folders Explorer Bar in Windows Explorer—it won’t work properly if you right-click on a folder in the Details pane.
Reminder: Won’t work from the Details pane
It is important that you launch the Dir Commander from the Folders Explorer Bar In Windows Explorer. If you right-click on a folder in the Details pane in Windows Explorer or launch it from a My Computer window, Dir Commander will display the contents of the parent folder.
When you’re in Windows Explorer, simply right-click on a folder in the Folders Explorer Bar and select Dir Commander from the context menu, as shown in Figure I.
|You can launch the Dir Commander simply by right clicking on a folder in the Folders Explorer Bar and selecting its command from the context menu.|
Once you select the command, you’ll momentarily see a Command Prompt window appear on the screen. (In Windows 98/Me the window is titled MS-DOS Prompt.) The batch file causes this as it launches the HTA. You’ll then see the Dir Commander dialog box, as shown in Figure J.
|You’ll use the options in the Dir Commander dialog box to configure the Dir command.|
To use the Dir Commander, you simply select the options corresponding to the Dir command line parameters that you want to use and then click the OK button. If you need assistance in understanding how the options in the Dir Commander dialog box correspond to the Dir command’s parameters, click the Help button. (I’m going to assume that you already understand how the Dir command line parameters work—otherwise you wouldn’t want to use this utility.)
Not all parameters are present
As you’ll notice, I didn’t implement all of the Dir command line parameters in the Dir Commander. Instead, I only chose those that seemed to be the most useful.
For example, suppose that you display only the filenames of the files in the Downloads directory and want them sorted by extension. If so, you’d select the check box next to the Display Attributes panel and then select the Directories and Use Opposite check boxes. You’d then select the check box next to the Display Sort panel and then select the By Extension check box. You’d then select the Bare radio button in the Display Format panel and click OK.
When you do, you’ll see the Command Prompt window appear on the screen showing the results of the Dir command you selected, as shown in Figure K.
|A Command Prompt will appear on the screen showing the results of the Dir command you selected.|
This window will appear right over the top of the Dir Commander dialog box, which will remain on the screen to allow you to easily issue subsequent Dir commands. However, before you can use the Dir Commander again, you must close the open Command Prompt window. If you don’t, the Dir Commander won’t work.
When you return to the Dir Commander dialog box, you can click the Show Command Line button to see the Dir command that was just issued, as shown in Figure L. This comes in handy if you like the results of this particular command and want to use it again as part of another operation, such as redirecting the results to a data file. When you’re done with Dir Commander, just click the Close button.
|If you click the Show Command Line button, you'll see the command line that the Dir Commander just issued.|
Removing the command from the Folder context menu
If at a later date, you decide that you want to remove the Dir Commander command from the Folder context menu, you’ll discover that you can’t do so from within the Edit File Type dialog box in Windows Me, Windows 2000, and Windows XP—even though there is a Remove button. When you select the Dir Commander Action in the list, the Remove button remains inactive. (In Windows 98, you can select the Dir Commander Action in the list and then click the Remove button.)
To remove the Dir Commander command from the Folder context menu in Windows Me, Windows 2000, and Windows XP, you’ll need to delve into the registry and manually delete the command. Fortunately, it’s an easy procedure.
To do so, just launch the Registry Editor by accessing the Run dialog box and typing Regedit.exe in the Open text box. Once the Registry Editor is up and running, navigate to the HKEY_CLASSES_ROOT\Folder\shell key and you’ll see a subkey titled Dir_Commander. Simply right-click on the Dir_Commander subkey and select the Delete command. When you do, you’ll be prompted to confirm the delete operation. If you’re sure that you selected the correct subkey to delete, just click Yes. Then, close the Registry Editor.
Greg Shultz is a freelance Technical Writer. Previously, he has worked as Documentation Specialist in the software industry, a Technical Support Specialist in educational industry, and a Technical Journalist in the computer publishing industry.