CTT - Compare Tree&Text for Windows — V1.0
(C) 1991-2021 Giuliano Artico


0. Introduction

ctt.exe is a command-line utility designed to compare one or more files contained in a given directory with files contained in a target directory. The program runs in console mode under any version of Windows XP/Win7/Win10, both 32-bit and 64-bit.

The program supports two operative modes as follows.

Tree compare mode or «Tree Mode» for short
Purpose: quickly compare files in a directory and its subdirectories and delete some of them with various criteria if desired, e.g. to check/purge a backup.
This mode emulates the excellent MS-DOS program CompTree 1.81 by Allan Hoiberg (Denmark) and may be considered as a port of it to Windows system with few enhancements. All options, errorlevel codes and beep tones of CompTree are supported with the same meaning (see the differences in ¶ 4).
Text compare mode or «Text Mode» for short
Purpose: compare a single source file with a target file by lines or by blocks and display differences. Here the behavior is interactive.
Run the program at the Windows prompt with the following general syntax:
ctt.exe SourceSpec TargetSpec [options]
The parameters SourceSpec and TargetSpec are mandatory in Tree Mode and optional in Text Mode. The choice of either operative mode is automatically determined by the specification SourceSpec.
Options are specific for each mode (see below).
Results are shown on the console and may be optionally logged into a report file.

Back to summary.

1. Tree compare mode

The program will execute in Tree Mode if either the parameter SourceSpec is a folder/drive or contains a wildcard character («*/?»). However, if SourceSpec matches a single file in the given directory, the Text Mode will be selected instead. Anyway you may force the Tree Mode execution by specifying the option /TR.
Note. if the executable file is renamed as ct.exe, then all the features of the Text Mode are hidden and the program is in effect a complete emulation of CompTree.
The files corresponding to SourceSpec may be located in all subdirectories or in those down to a specified depth (see option /S).
TargetSpec is usually a drive or directory and files in SourceSpec will be compared to the ones in TargetSpec with the same name, respecting the tree structure for those contained in subdirectories.

TargetSpec may also be a single file (in this case all files in SourceSpec will be compared to it) but it cannot contain wildcard characters.

1.1. Command line options for Tree Mode

In the following option list, the differences with respect to CompTree are marked with [New]. See also the remarks in ¶ 3.
Include subdirectories of SourceSpec in the source scan and compare files there to the files in identical TargetSpec subdirectories.
[New] If an optional number n is specified, only the subdirectories down to level n are considered. E.G., /S1 will include files in the given directory and in all subdirectories at first level.
Use /S without any parameters to consider all subdirectories.
Use /S0 or /S- to restore the default setting (no subdirectories).
This option has several modifiers that can be used to delete source files, subject to the result of comparison.
  • /D (without any parameters): delete source files and subdirectories that match.
  • /DF: delete only files (i.e., even if a subfolder remains empty, it is kept).
  • /DB: delete also base directory (provided it remains empty and it is not the current directory).
[New] The following modifiers of the option /D where not supported in CompTree.
  • /D!D: delete source file if source and target have different sizes.
  • /D!E: delete source file if any error occurs (compare, size, open).
  • /D!M: delete source file if the corresponding one is missing in target.
  • /D!A: delete source file if match fails, same as /D!D!E!M.
  • /DR: don't delete read-only files
  • /DH: don't delete hidden files
  • /DS: don't delete system files
Most modifiers may be combined, e.g. /D!MHS deletes files that are missing in target, but don't delete those of them that are hidden or system.
The modifiers !A, !D, !E, !M may cause unrecoverable loss of data! Therefore, if one or more of them are specified, the program copies the deleted files into a new subfolder of an appropriate backup folder (see ¶3).
You may assign the backup folder with the modifier :backupdir. E.g., if you specify /D!A:D:\backup, all deleted files will be copied to a new subdirectory CT0001, CT0002,... of D:\backup, replicating the subdirectory structure . The :backupdir token must be the last specified parameter, to the right of other possible modifiers.
The default backup folder may vary, depending on the program folder and Windows version (see ¶ 3, remark 4).
If you don't want to backup delete files, specify :nul as a backup directory, e.g. /D!M:nul.
Use /D- to restore the default setting (don't delete any files).
Store results in a file report. This option has several modifiers, as described below.
  • logfile: name of the report file. By default, the results are appended to the existing file. The default file name is either ctt.log or ct.log,depending on the name of the executable file.
  • O: Overwrite existing report file.
  • C: log file when compare fails (including files with different sizes).
  • F: log file when open or read fails (File error).
  • M: log file when target is missing.
  • E: Log file if any error occurs (including read and open, but not missing target).
  • A: log all non-ok results (same as /LME).
  • K: log file when compare is successful.
  • R: log results too (OK, Target not found, Different file sizes, Compare error): in fact, when C, F, M, E, A or K is used, only source filenames are logged by default, no compare results.
  • Q: use quotes around file names containing spaces.
  • Q2: use quotes around all file names.
  • B: [New] write a bare list of files in the report, omitting the header and summary.
  • P: [New] add full path to file names.
  • Use /L- to restore default (report logging disabled).
Options can be combined, for example
to log successfully compared files to logfile, which is overwritten if it exists. Adding R to the command causes results to be logged too.
Note. Some modifiers together don't make much sense: for example, /LAKR and /L are equivalent.
No summary at end. This is the default behavior when a single file is specified.
Use /N- to restore the default setting.
Quick mode: assume that same size equals same contents.
With /Q2, the files are assumed to be identical provided they have both the same size and the same timestamp (last write access).
Use /Q- to restore default (byte-by-byte comparison for files with the same size).
No screen output. Only the progress of the process is displayed if console mode is selected (/C option).
Use /O- to restore the default setting.
Beep when finished. The following characters may be added to /B to get the effects described below.
  • No character or 1: play a short single-tone beep-.
  • 2: play a more arcade-like beep (this may be less suitable for an office environment).
  • R: play a beep determined according to the result of comparison, namely a rising tone for no errors, a falling tone otherwise.
  • K: beep only when no errors occurred.
  • [New] C: beep only when at least one compare error occurred.
  • [New] M: beep only when at least one file missing in target is found.
  • A: beep only when any error occurred.
Whenever it makes sense, the modifiers may be combined, e.g. /B2RK.
The modifiers K, C, M, A should be used separately, but if two or more of them are specified, they are applied in this order with decreasing precedence.
Use /B- to restore the default setting (no beep).
Console mode: show results in bottom line.
With /C2, the percentage is also shown (based upon number of processed files).
Use /C- to restore full display.
[New] Set the sound volume as a percentage, where n indicates a number in the range 0 to 100. Specify 0 to suppress all sounds.
Use /V without any parameters to restore the default value 20.
help options
    /? or /H: display a summary of the available options.
    Note. If the executable file name is other than ct.exe, use the /?? option instead (since in this case /? refers to the Text Mode).
  • /LOG?: displays logging options.
  • /B?: displays beep options.
  • /ERR?: displays DOS errorlevels.
  • /DEL?: displays details for /D option.
[New] The output of these screens can be redirected to a file.

1.2. System folder protection

The Windows and program folders (32 and 64 bit) are protected against writing and file deletion. More precisely:
  1. the /D option is disabled if SourceSpec indicates files in these directories or their subdirectories.
  2. it will not be possible to write the log to these directories (/L option) and not even assign a backup folder for deleted files inside them (/D option).

To change this behavior, you can assign a list of protected folders with the /$SYSPROTECT option as follows:

where the «*» element is an abbreviation in place of c:\Windows;C:\Program Files;C:\Program Files (x86).
CAUTION! This feature can be harmful: it must be used with extreme attention and awareness.

1.3. Errorlevels

The following errorlevel codes are returned by ctt.exe at the end of the execution and are the same as released by CompTree. Errorlevel codes can be read by batch files using the ERRORLEVEL variable. This way, a batch-file can automatically decide what to do after comparing two files.

1.4. Examples for Tree Mode

  1. Compare the entire tree of files in dir1 with those in dir2 and write the results in the file d:\txt\ct-log.txt, overwriting it if it already exists:
    ctt dir1 dir2 /s /lo:d:\txt\ct-log.txt
  2. Same as above, but deleting all files in dir1 that are identical to the corresponding in dir2 and also removing the directory dir1 if it will turn out that it is empty at the end of the process:
    ctt dir1 dir2 /s /db /lo:d:\txt\ct-log.txt
  3. The following command performs a process that is complementary to that of example 2, in the sense that it keeps all the files in the subtree of dir1 that are also present in the folder dir2, while it moves all files with missing target into a subdirectory of d:\backup. The name of this subdirectory is the first among ct0001, ct0002,,... that does not yet exist.
    ctt dir1 dir2 /s /l /d!m:d:\backup
    Note. You may use a different modifier. For example, /D!a will delete and move files when they are missing in the target folder or give compare error or have different size, keeping those that match exactly.
  4. Unlike example 1, here the modifiers of the /L option allow you to list only the files that match, so that the list produced can be used later to create a RAR archive that contains them. To be precise, these are the modifiers used:
    • «K» lists the files that match,
    • «B» produces a bare list of files (no headings, no summaries),
    • «P» includes the full path in file names.
    ctt dir1 dir2 /s /l O K B P :d:\txt\ct-log.txt
    rar a archive.rar @d:\txt\ct-log.txt

Back to summary.

2. Text compare mode

This part is derived by a small program that I wrote for my personal use in the Nineties to locate changes in different versions of source programs (.BAT, .TEX, .pl, etc.).

The program compares two text files, respectively called Source and Target, proceeding line by line and stopping when it identifies a pair of lines,in the first and in the second file, that are different from each other. If this happens, a portion of each line is displayed to highlight the differences.

The syntax for Text Mode is as follows:

ctt.exe [sourcefile [targetspec ]] [options]
If either file specification is missing, the program will prompt to enter them.

When the program stops to display differences, you can press several keys as described in the list below.

Display the list of available keystrokes.
Arrow keys, Ctrl+Left/Right, Ctrl+PgUp/PgDn
Move the cursor on the screen (this can be useful for screen reader users to carefully inspect text).
Keystroke summary.
Move the cursor right/left to the next character with a different color attribute, that is,to the point where the differences begin.
Return, Space, PgDn
Find the next pair of different lines, by moving forward.
Backspace, PgUp
Find the next pair of different lines, by moving backwards.
Advance one line in both files.
Go back one line in both files.
Lowercase «s», «1», F5
Advance one line in Source.
Lowercase «t», «2», F6
Advance one line in Target.
Uppercase «S», «3», Shift+F5
Go back one line in Source.
Uppercase «T», «4», Shift+F6
Go back one line in Target.
Jump to last/first marked pair of lines.
Jump to next/previous marked pair of lines.
Mark the displayed pair of lines shown last, to be able to easily return to that point (see F7/Shift+F7, F8/Shift+F8).
Jump to specific lines. After pressing F10, you may type:
  • a line number to jump to that line in both files, or
  • two numbers separated by «/» to jump to the lines corresponding to the two numbers in Source and Target respectively.
Jump to the first/last line in both files.
End of session
Press Esc or Alt+F4 to terminate the comparison. The program displays a summary and prompts to exit. You may press Y to exit, N to start again with a new pair of files, or Esc to recover the current session at the last displayed line.
The operation described so far is properly called Text Mode, and it is ideally applied when both files consist of normal text.
Otherwise, if at least one of the two files is not a text file, the binary mode is activated, in which the comparison takes place by blocks and not by lines. All actions described above remain valid. By default, blocks are 60 bytes, but you can specify a different block length with the / R option.

2.1. Command line options for Text Mode

See the remarks in ¶ 3.
f1 and f2 denote two numbers to set the frequencies of the tones for sound highlighting of color attributes on screen. The default frequencies are 1024 and 1367, corresponding to the notes C and F of the fifth octave of piano.
Use /A- to restore the default values.
Ignore case in text compare mode. Use /I- to restore default (case sensitive comparison).
Store results in a file. The default name of the report is ctt.log. You may specify a different name by adding a colon and the file specification.
You may add the optional modifier «O» to overwrite the report file, if it already exists.
Use /L- to restore default (report logging disabled).
No keyboard action. The program does the processing without displaying differences. This option should be used together with the /L option.
/NP prevents the program from prompting for a new operation at end.
Use /N- to restore default displaying.
n specifies the block size in bytes for binary comparison: it can range from 1 to 4096.
Use /R without any parameters to restore the default value of 60.
Force the choice of the operating mode by specifying one of the modifiers listed below.
  • /TR: force start in Tree Mode, even for a single file.
  • /TX: force start in Text Mode.
  • /TXB: force binary comparison in in Text Mode.
  • The optional number n indicates the file size of Sourcefile in megabytes and defines a threshold above which files will be compared in Tree Mode. However, if the «X» modifier is present, it has the precedence and files will still be compared in (possibly binary) Text Mode. The default treshold value is 10.
  • Use /T- to restore the default settings.
Set the sound volume as a percentage, where n indicates a number in the range 0 to 100. Specify 0 to suppress all sounds.
Use /V without any parameters to restore the default value 20.
ignore characters in comparison. The modifiers listed below are available.
  • 0: plain comparison, no character wil be ignored.
  • 1 (or no parameter): ignore blanks at end of lines (default).
  • 2: ignore blanks at begin of lines.
  • 3: ignore blanks at begin and end of lines.
  • 4: ignore all characters in the CharList defined with the /Y option
Characters used to identify binary files. charlist is a comma-separated list of numbers in the range 0-31. You can specify a sequence of contiguous numbers with the abbreviation m-n, e.g. /X0-8,14-31.
The default list is: 0-6,14-25,27-31.
Use /X without any parameters or /X- to restore the default list.
Note. Characters 10 and 13 will be never included in this list. For the remaining characters, it is the user's responsibility to indicate a proper character list.
Characters to be ignored in text comparison. charlist is a comma-separated list of numbers in the range 0-32. You can specify a sequence of contiguous numbers with the abbreviation m-n, e.g. /Y9-13,26
Default list: 9,12,13,32.
Use /Y without any parameters or /Y- to restore the default list.
Help options
  • /? or /H: display a summary of the available options.
  • /??: summary of options for the Tree Mode.
The output of these screens can be redirected to a file.
The options /I, /W, /X are ignored if binary comparison is in effect.

2.2. Remarks about Text Mode

The following remarks apply to Text Mode only. Note. The comparison method adopted by CTT in Text Mode may appear rudimentary to a sighted user. Unfortunately, the most effective tools, such as the PSPad text comparator, are not friendly to blind users, who interact with the PC through a screen reader. I want to hope that the Text Mode of this application can still be of benefit to someone, as it has been for myself.

Back to summary.

3. General remarks

The remarks in this section apply both to Tree Mode and to Text Mode.
  1. All options are case insensitive.
  2. You can specify any option with the CTT_OPT environment variable. If an option is present both in the environment variable and in the command line, the latter overrides the former. Moreover, in these cases, the default settings can be generally restored at command line by the option followed by a minus sign, e.g. /B-. See more details in ¶ 1.1 and (¶ 2.1.
  3. With reference to the previous item, you may set a fixed name for the report file with the following command at the Windows prompt:
    set ctt_opt=/l:d:\somedir\somefile.txt
    and later you can simply use /L- to disable report logging or /LO to overwrite the report in the file d:\somedir\somefile.txt.
  4. Here is the default list of folders, in order of decreasing precedence, in which the program will write the report (/L option) and will place the backup copies of deleted files (/D option of Tree Mode):
    • the current directory;
    • the directory of the program executable file;
    • the subdirectory CT in the user documents directory;
    • the directories listed in the TEMP environment variable;
    • the system temporary directory.
    However, note that the backup directory will never be placed in a subdirectory of the source file directory (see the /D option with modifiers !a, !D, !E,!M).
  5. when a process takes a longer time, a rhythmic clicking sound is emitted. The volume of this tick if fixed and cannot be adjusted. Use the /V0 option to suppress it.

Back to summary.

4. Notes for CompTree users

If you are familiar with CompTree, you can rename the executable file as ct.exe. This way, you can use exactly the same commands you were used to. You can continue to use your old batch files because all options, errorlevel codes, logging features and beeps have been preserved.

The new features and additions are sumarized below (see more details in ¶ 1).

/B option
New C and M modifiers.
/D option
New !A, !D, !E, !M, R, H and S modifiers.
The !A, !D, !E, !M modifiers allow to delete files that don't match. In this case , deleted files are saved in a backup directory, that can be assigned with the :backupdir modifier.
/L option
New B and P modifiers.
Some new information in the log header (free memory during process, command line, environment variable if set, list of protected folders) and in the summary (compare speed).
/S option
A new numeric parameter allows to specify the depth of subdirectory to limit file scanning.
/V option
New option to set the sound volume.
Invalid options are ignored
If you specify an invalid option, the program simply ignores it and gives no error messages.
Environment variable
All options can be included in the CTT_OPTd environment variable. Every option has a modifier to restore default values from command line.
System folder protection and /$SYSPROTECT option
The Windows and program directories are protected against writing and file deletion.
The /$SYSPROTECT option can be used to set protection for more directories.
Reserved or invalid file names
Terms as PRN, LPT1, etc., are not accepted in file names or path.
If a report file or backup directory contains such an element, the default is assumed. The same applies if the file specification is not syntactically valid.
Output redirection
added support of output screen redirection (for help screen only).
Fixed file size limitation
The comparison works correctly even on files larger than 2 Gb.

Back to summary.

5. License

The CTT program can be used and distributed free of charge. Nobody is authorized to ask for compensation for the supply, for the installation, for the use or in any case for any service concerning this software.
The CTT program is distributed "as is". No warranty of any kind is expressed or implied. You use at your own risk. The author and his associates will not be liable for data loss, damages, loss of profits or any other kind of loss while using or misusing this software.

5.1. Download

The program is distributed as a ZIP compressed archive that contains the executable file ctt.exe and this manual ctt.htm.
After unpacking the archive, place the executable file in any directory that is not a Windows protected directory. For example, a good location for it might be something like C:\util. The ideal would be that this folder was also added to the system path.

As mentioned in ¶ 1, you can rename ctt.exe as ct.exe (or, if you like, make a second copy with this name) in order to have only the features of CompTree.

Click here to download the latest version of the CTT program.

Click here to contact the author by e-mail

Author's home page (Italian), author's curriculum (English).

Back to summary.