Program Dirdemo; {$R+ Enables Ctrl-C breaks too} Uses Dos; { Filename: DirDemo.pas } { Coder : Jacob V. Pedersen } { Coded : 4-8-1990 } { Amiga : Christen Fihl 1991 } { Purpose : Example } { Make a file listing with attributes shown } {========================================================================== Exercise for you: Make code to calculate the total size of the directory, and the total number of files in the directory ==========================================================================} CONST DisplayAttr: Boolean = True; { Show file attributes ? } DisplayTime: Boolean = True; { --------- time stamp ? } DisplayDate: Boolean = True; { --------- date stamp ? } OnlyArcFiles: Boolean = False; { Only search for A flags } PauseParam: Boolean = False; { Pause after each screen?} DirName: DirStr = ''; { Current directory, initialized } VAR DosData : SearchRec; { Information from DOS } Dt : DateTime; { Holds the date and time } N : Integer; S : String; {$Ifdef CPU86} Const DirFlags = '---vda----------'; {$Endif} { Traverse the directory while displaying the file information } Procedure ShowDir( DirName : DirStr ); Var N,LineCounter : Integer; Attr: Word; Ch : Char; DirFlag: String[16]; Begin DirFlag:=DirFlags; LineCounter := 0; If OnlyArcFiles then Attr:=Archive else Attr:=AnyFile; FindFirst( DirName, Attr, DosData ); With DosData,Dt DO While (DosError = 0) DO Begin If (LineCounter = 24) AND PauseParam then Begin LineCounter := 0; Write('Press Return'); ReadLn; End; Inc(LineCounter); UnpackTime(Time,Dt); Write(Name,'':20-Length(Name)); if Attr and VolumeID <> 0 then Write('':10) else If Attr and Directory <> 0 then Write('' :10) else Write(Size:10); If DisplayAttr then Begin Write(' '); for N:=Length(DirFlag) downto 1 do if Attr and (1 shl (N-1)) <> 0 then write(DirFlag[N]) else write('-'); End; If DisplayDate then Write(Day:6,'-',Month div 10,Month mod 10,'/',Year); If DisplayTime then Write(Hour:6,'.',Min div 10, Min mod 10); Writeln; FindNext(DosData); End; { while doserror = 0 } End; { ShowDir } BEGIN { main } for N:=1 to ParamCount do begin {Read all parameters from command line} S:=ParamStr(N); if (Length(S)=2) and (S[1] in ['-','/']) then case UpCase(S[2]) of 'A': OnlyArcFiles:=True; 'P': PauseParam :=True; 'D': {$Ifdef Amiga} PatternProc:=@PCDosPattern {$Endif}; 'A': DisplayAttr:=False; 'T': begin DisplayTime:=False; DisplayDate:=False; end; else Writeln('Bad parameter: ',S); end else DirName := S; end; {$Ifdef Amiga} if DirName='' then if PatternProc=@PCDosPattern then Dirname:='*.*' else DirName:='#?'; {$Else} if DirName='' then DirName:='*.*'; {$Endif} ShowDir(DirName); END.