home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_07 / HISPEED1.ZIP / DOSDEMO / DIRDEMO.PAS next >
Pascal/Delphi Source File  |  1991-07-02  |  4KB  |  121 lines

  1. Program Dirdemo;
  2.  
  3. Uses Dos;
  4.  
  5. { Filename: DirDemo.pas       }
  6. { Coder   : Jacob V. Pedersen }
  7. { Coded   : 4-8-1990          }
  8. { Purpose : Example           }
  9.  
  10. { Gives a listing of the current directory. }
  11.  
  12. { Exercise:
  13.  
  14.     Make code to calculate the total size of the directory, and
  15.     the total number of files in the directory.                  }
  16.  
  17. CONST
  18.         DisplayAttr     = TRUE;         { Show file attributes ? }
  19.         DisplayTime     = TRUE;         { --------- time stamp ? }
  20.         DisplayDate     = TRUE;         { --------- date stamp ? }
  21. VAR
  22.         DosData         : SearchRec;    { Information from DOS }
  23.         DirName         : DirStr;       { Current directory }
  24.         Dt              : DateTime;     { Holds the date and time }
  25.         PauseParam      : Boolean;      { Pause after each screen? }
  26.  
  27.  
  28. Function Spaces( Number : Byte ) : String;
  29. Var S : String;
  30. Begin
  31.   FillChar(S[1],Number,' ');
  32.   S[0] := Chr(Number);
  33.   Spaces := S;
  34. End; { Spaces }
  35.  
  36.  
  37. { Make a filename presentable. }
  38. Function LookGood ( FileName : String ) : String;
  39. Var
  40.         PuncPos : Byte;
  41. Begin
  42.   PuncPos := Pos('.',FileName);
  43.   If (PuncPos > 1) then
  44.     Insert(Spaces(9-PuncPos),FileName,PuncPos);
  45.   LookGood := FileName + Spaces(12-Length(FileName));
  46. End; { LookGood }
  47.  
  48.   
  49. { Pad a string with nulls, until it has a length that equals Lng. }
  50. Function AddZero ( Number : Integer; Lng : Byte ) : String;
  51. Var
  52.   WorkRes : String;
  53. Begin
  54.   Str(Number,WorkRes);
  55.   While Length(WorkRes)<Lng do Insert('0',WorkRes,1);
  56.   AddZero := WorkRes;
  57. End; { AddZero }
  58.  
  59.  
  60. { Traverse the directory. Display the file information. }
  61. Procedure ShowDir( DirName : DirStr );
  62. Var
  63.         FileCounter : Integer;
  64.         Ch : Char;
  65. Begin
  66.   FileCounter := 0;
  67.   FindFirst( DirName+'*.*', AnyFile, DosData );
  68.   While (DosError = 0) DO
  69.     Begin
  70.       If (FileCounter = 24) AND (PauseParam) then
  71.         Begin
  72.           Write('Press SPACEBAR');
  73.           Repeat until ' '=ReadKey;
  74.           DelLine;
  75.           FileCounter := 0;
  76.         End;
  77.  
  78.       With DosData DO
  79.         Begin
  80.           Inc(FileCounter);
  81.           Write(LookGood(Name));
  82.           If (Attr and Directory > 0) then
  83.             Write('<DIR>' :10)
  84.           ELSE
  85.             Write(Size:10);
  86.           If (DisplayAttr) then
  87.             Begin
  88.               Write('   ');
  89.               If (Attr And ReadOnly > 0) then
  90.                 Write('r') else Write('-');
  91.               If (Attr And Hidden > 0) then
  92.                 Write('h') else Write('-');
  93.               If (Attr And SysFile > 0) then
  94.                 Write('s') else Write('-');
  95.               If (Attr And VolumeID > 0) then
  96.                 Write('v') else Write('-');
  97.               If (Attr And Directory > 0) then
  98.                 Write('d') else Write('-');
  99.               If (Attr And Archive > 0) then
  100.                 Write('a') else Write('-');
  101.             End; { displayattr }
  102.           UnpackTime(Time,Dt);
  103.           With Dt DO
  104.             Begin
  105.               If (DisplayDate) then
  106.                 Write(Day:6, '-',AddZero(Month,2),'/',Year);
  107.               If (DisplayTime) then
  108.                 Write(Hour:6, '.',AddZero(Min,2));
  109.             End; { with dt do }
  110.           Writeln;
  111.         End; { with dosdata do }
  112.       FindNext(DosData);
  113.     End; { while doserror = 0 }
  114. End; { ShowDir }
  115.  
  116. BEGIN { main }
  117.   PauseParam := (ParamStr(1) = '/p') OR (ParamStr(1) = '/P');
  118.   DirName := FExpand(''); { Get current directory. }
  119.   ShowDir(DirName);
  120. END.
  121.