program matchdir; (********************************************************************) { } { date 1-20-85 Author: Steve Mitton } { } { version 1.0 } { } { THIS PROGRAM COMPARES THE DIRECTORIES OF DRIVE 'A' & 'B'. } { IT OUTPUTS THE FILES UNIQUE TO 'A' AND UNIQUE TO 'B'. } { } (********************************************************************) const searchdir = 17; setdma = 26; searchnext = 18; crlf = ^M^J; type file_name = array [1..11] of char; fcb_type = record dr : byte; name : file_name; data : array [12..35] of byte end; file_str = string[11]; dir_type = array [1..63] of string[11]; var areg, i, sizeA, sizeB, num_unique_A, num_unique_B : byte; dma : array [1..128] of byte; filenameA, filenameB, uniqueA, uniqueB : dir_type; procedure readfilename(reg : byte; var astring : file_str); (*************************************************************************) var i, start : integer; abyte : byte; function screen(object : byte) : char; { This function ensures all characters have high bit set to 0 } { Without this function write protected files would appear } { different that non write protected files. } begin if object > 128 then object := object - 128; screen := chr(object) end; begin astring := ''; case reg of { reg holds start of fcb in dma } 0 : start := 0; {location is the reg shifted left five times} 1 : start := 32; 2 : start := 64; 3 : start := 96; end; {rem 1st byte of fcb the dr byte} for i := 2 to 12 do begin abyte := dma[i + start]; astring := astring + screen(abyte) end end; procedure sort_dir(sizedir : byte; var dir : dir_type); (*************************************************************************) var small, temp : file_str; i, j, location : byte; begin for i := 1 to sizedir - 1 do begin small := dir[i]; location := i; { find the smallest item in sublist beginning at position i+1 } for j := i+1 to sizedir do if dir[j] < small then begin small := dir[j]; location := j end; { now switch the smallest item with the one at position i } temp := dir[i]; dir[i] := dir[location]; dir[location] := temp end { for i } end; { sort } procedure comparedrive(size1, size2 : byte; var filedir1, filedir2, unique_files : dir_type; var num_unique : byte); (*************************************************************************) var i, current_file : byte; found : boolean; begin num_unique := 0; for i := 1 to size1 do begin found := false; current_file := 1; while (not found) and (current_file <= size2) do begin if filedir1[i] = filedir2[current_file] then found := true; current_file := succ(current_file) end; if not found then begin num_unique := succ(num_unique); unique_files[num_unique] := filedir1[i]; end end end; procedure read_dir(drive : byte; var directory : dir_type; var num_files : byte); (*************************************************************************) var afile : fcb_type; procedure initfcb(fname : file_name; drive : byte); begin with afile do begin dr := drive; name := fname; fillchar(data, 23, 0); end end; begin initfcb('???????????', drive); num_files := 0; areg := Bdos(searchdir, addr(afile)); while areg <> 255 do begin if areg in [0..3] then begin num_files := succ(num_files); readfilename(areg, directory[num_files]) end; areg := BDOS(searchnext) end end; procedure print_results(dr1, dr2 : char; var U_file : dir_type; numfiles : byte); (*************************************************************************) var i : byte; begin writeln('Comparing drive ', dr1, ' to drive ', dr2, ' . . .'); writeln(' These files are on drive ', dr1, ' but not drive ', dr2, ':'); if numfiles = 0 then writeln(crlf, ^G, 'ALL DISK ', dr1, ' files are found on ', dr2) else for i := 1 to numfiles do begin write (U_file[i], ' | '); if i mod 4 = 0 then writeln end; writeln end; (*************************************************************************) (*************************** MAIN PROGRAM ********************************) (*************************************************************************) begin clrscr; writeln('MATCHDIR.COM version 1.0 ', crlf, 'Copyright (c) 1985 by Steve Mitton NPS Monterey, Ca', crlf, 'Released to Public Domain for non-commercial use'); gotoxy(1,12); writeln(' ??? Compare Directories ???'); writeln; writeln('Insert disks into drive A and B for a directory comparison.'); writeln('This program only compares the filename NOT file content.'); writeln('Press any key to start'); repeat until keypressed; clrscr; writeln; bdos(setdma, addr(dma)); read_dir(1, filenameA, sizeA); read_dir(2, filenameB, sizeB); if (sizeA <> 0) and (sizeB <> 0) then begin sort_dir(sizeA, filenameA); sort_dir(sizeB, filenameB); comparedrive(sizeA, sizeB, filenameA, filenameB, uniqueA, num_unique_A); comparedrive(sizeB, sizeA, filenameB, filenameA, uniqueB, num_unique_B); print_results('A', 'B', uniqueA, num_unique_A); writeln; print_results('B', 'A', uniqueB, num_unique_B) end else begin if sizeA = 0 then writeln ('No files found of drive A'); if sizeB = 0 then writeln ('No files found of drive B'); end end.