The magazine of the Melbourne PC User Group

Compare Any Two Files Displayed In Windows Explorer
Keith Phillips

The command line utility FC.EXE compares two files. If they are identical, it reports No differences encountered. If they are different it displays a list of the differences. The programs described below run FC.EXE so the tedious and error prone task of typing the command line is eliminated. A few mouse clicks in Windows Explorer compare the two files.

There are four stages in comparing the files:

  1. Select files in Windows Explorer and SendTo a shortcut.
  2. The shortcut sends the file names to a batch program.
  3. The batch program makes directory listings for the files.
  4. A Qbasic program reads the directory listings and runs FC.EXE.
Qbasic is on the Windows 95, 98, 98SE and Me CD-ROMs. Use Windows Explorer to make a C:\QB directory (or a name of your choice). Search the Windows CD-ROM for Qbasic and copy Qbasic.exe and Qbasic.hlp into C:\QB. Also, use Windows Explorer to make a C:\CLU (Command Line Utility) directory, or a name of your choice.

Make The Batch Program MATCH.BAT 

Using a text editor such as Notepad, type in the batch code and Save As MATCH.BAT in the C:\CLU directory. When MATCH.BAT is executed the %1 parameter is replaced by the file name sent from Windows Explorer. MATCH.BAT makes the file's directory listing in the C:\CLU\DIR-LIST file. (Note: The program listing is shown below, or may be downloaded from MATCH.BAT

Make The Shortcut Match Two Files

In Windows Explorer, open the C:\CLU directory. If the C:\Windows\SendTo directory is not visible in the left pane of Explorer, use the vertical scroll bar to move it into view. Right drag the MATCH.BAT icon and drop it on the SendTo icon. In the pop-up menu click Create Shortcut(s) Here.

In Windows Explorer, open the SendTo directory, right click the Shortcut to Match.bat and rename it Match Two Files. Right click the shortcut again and select properties. Edit the Program tab (Figure 1) and the Screen tab (Figure 2). Click Apply and OK.

Make A Shortcut To Run QBASIC.EXE

In Windows Explorer open the C:\QB directory. Right click the QBASIC.EXE icon, and in the pop-up menu click Create Shortcut. Right click the shortcut and rename it RUN Qbasic. Right click the shortcut again and select properties. Edit the Program tab (Figure 3) and the Screen tab (Figure 2). Click Apply and OK.

NOTE that the Working text field in the RUN Qbasic shortcut is blank. RUN Qbasic doesn't set the working directory so the shortcut can be used to make Qbasic programs in any directory. The directory that is open in Windows Explorer is the working directory.

Use RUN Qbasic To Make MATCH.BAS

Copy the RUN Qbasic shortcut from C:\QB into C:\CLU. In the open C:\CLU directory in Windows Explorer, double click the shortcut. Type in the Qbasic code, Save As MATCH.BAS and close Qbasic.exe. MATCH.BAS is saved in C:\CLU because it is the working directory.

In the MATCH.BAS program, the command line to run FC.EXE is executed in a temporary batch program because the SHELL statement in Qbasic can't execute very long command lines.

Select Files To Be Matched

There are two ways to open the SendTo menu in Windows Explorer. Left click a file icon and in the main menu pull-down the File menu, OR, right click any icon to pop-up its context menu. In either menu, point the mouse cursor to SendTo to display the SendTo menu. The first method works only with files, the second method works with directories and files.

How To Match Two Files

In Windows Explorer open the directory that contains the first file. Open the SendTo menu and click the Match Two Files shortcut. A short beep signals that the first file has been selected and a message screen displays briefly and then closes. You can still see which file was selected because its name remains highlighted in Windows Explorer.

If the second file is in another directory, open that directory. Select the second file and SendTo the Match Two Files shortcut. Two beeps signal that two files have been selected and a message screen displays briefly. The second file name remains highlighted in Windows Explorer. Then the report from FC.EXE is displayed in Notepad. 

If you accidentally select the same file twice, an error message appears in Notepad and the selection is cancelled. You can also recover if you accidentally selected a wrong first file. Select it again to cancel the selection.


Figure 1. Match Two Files Properties Screen.


Figure 2. Screen Properties.


Figure 3. RUN QBasic Properties Screen.

There Is Another Use For These Programs!

Windows Explorer is an almost perfect program but it doesn't give the option to print a listing of the files in a directory. In Windows Explorer, right click a directory instead of a file and in the SendTo menu click the Match Two Files shortcut. The directory listing is displayed in a Notepad Window. You can read the listing or print it or Save As a file. You can edit out any unwanted information before printing or saving.

My thanks to Michael Mileo, IT Manager, Applied Chemistry Department, RMIT University, for testing this program in Windows Me. 



Listing for MATCH.BAS



Listing for MATCH.BAT

Reprinted from the August 2001 issue of PC Update, the magazine of Melbourne PC User Group, Australia