home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / pcmag / vol8n04.arc / NEWEXIST.PAS < prev    next >
Pascal/Delphi Source File  |  1988-10-06  |  2KB  |  79 lines

  1. PROGRAM NewExist;
  2. (*Demonstrates using FSearch to
  3.   test for file existence.*)
  4. USES DOS;
  5. CONST Reps = 100;
  6. VAR
  7.   start, total, N, IfTime : LongInt;
  8.   example                 : PathStr;
  9.  
  10.   FUNCTION time100ths : LongInt;
  11.   VAR H,M,S,F : Word;
  12.   BEGIN
  13.     GetTime(H,M,S,F);
  14.     Time100ths := (((((LongInt(H)*60)+M)*60)+S)*100)+F;
  15.   END;
  16.  
  17.   FUNCTION Exists(Name : PathStr) : Boolean;
  18.   VAR F : File;
  19.   BEGIN
  20.     Assign(F,Name);
  21.     {$I-} Reset(F); {$I+}
  22.     IF IOresult = 0 THEN
  23.       BEGIN
  24.         close(F);
  25.         Exists := TRUE;
  26.       END
  27.     ELSE Exists := FALSE;
  28.   END;
  29.  
  30.   PROCEDURE Announce(method, kind : String);
  31.   BEGIN
  32.     WriteLn(reps,' repetitions of ',method,' with ',kind,' file.');
  33.   END;
  34.  
  35.   PROCEDURE Report(T : LongInt);
  36.   BEGIN
  37.     WriteLn('That took ',T div 100,'.',T mod 100,' seconds.');
  38.   END;
  39.  
  40. BEGIN
  41.   (*Time a minimal IF loop*)
  42.   start := time100ths;
  43.   FOR N := 1 to reps DO IF TRUE THEN;
  44.   IfTime := time100ths - start;
  45.   (*Try example files on floppy disks and on hard disks.*)
  46.   example := 'NEWEXIST.PAS';
  47.  
  48.   Announce('Exists','existing');
  49.   start := time100ths;
  50.   FOR N := 1 to reps DO
  51.     IF NOT Exists(example) THEN;
  52.   total := time100ths - start - IfTime;
  53.   Report(total);
  54.  
  55.   Announce('FSearch','existing');
  56.   start := time100ths;
  57.   FOR N := 1 to reps DO
  58.     IF FSearch(example,'') = '' THEN;
  59.   total := time100ths - start - IfTime;
  60.   Report(total);
  61.   example := 'QWERTYUI.OP';
  62.  
  63.   Announce('Exists','non-existing');
  64.   start := time100ths;
  65.   FOR N := 1 to reps DO
  66.     IF Exists(example) THEN;
  67.   total := time100ths - start - IfTime;
  68.   Report(total);
  69.  
  70.   Announce('FSearch','non-existing');
  71.   start := time100ths;
  72.   FOR N := 1 to reps DO
  73.     IF FSearch(example,'') <> '' THEN;
  74.   total := time100ths - start - IfTime;
  75.   Report(total);
  76.   WriteLn;
  77.   ReadLn;
  78. END.
  79.