home *** CD-ROM | disk | FTP | other *** search
- program DirList;
- {$C-}
-
- { DirList version 1.1 -- last updated 6/13/87 by Alexander Morris }
- { }
- { This Program will display a Directory Listing including all System, }
- { Hidden, and Read Only files, along with the File Attribute Status, }
- { including Archive Status. }
- { }
- { v1.0 written by David W. Terry 4/29/85 }
- { Last updated by Alexander Morris 6/13/87 -- corrected many bugs }
-
- type
- fwstring = string[255];
- str2 = string[2];
- str6 = string[6];
- str9 = string[9];
- str15 = string[15];
- FileList = array[1..1024] of record
- Name: string[13];
- Attrib: byte;
- Size: real;
- Date,Time: str9;
- end;
- regpack = record
- ax,bx,cx,dx,bp,si,di,ds,es,flags:integer
- end;
- var
- line: fwstring;
- List: filelist;
- FileMask: str15;
- X,total: byte;
- recpack: regpack;
- Hidden,System,ReadOnly,Normal,Archive,Dircty: boolean;
- ss,dd,t: string[30];
- i:integer;
-
- const
- H ='Hidden '; S ='System '; R ='Read Only '; N ='Normal '; A ='Archive '; D ='Dir';
- HN='------ '; SN='------ '; RN='--------- '; NN='------ '; AN='------- '; DN='---';
-
- procedure FastWrite(stringfld:fwstring; fgatt,bgatt,cursor:integer);
- {substitute any Quick Screen Write Procedure for this. All output has
- already been converted to strings}
- begin
- TextColor(fgatt);
- TextBackGround(bgatt);
- if cursor=1 then Write(stringfld) else
- if cursor=2 then Writeln(stringfld);
- end;
-
- procedure Directory(FileMask: str15; var List: FileList; var Total: byte);
- var Dta: string[44];
-
- function FileSize: real; { decypher the File's Size in Bytes }
- var Size: real;
- Byte1,Byte2,Byte3,Byte4: byte;
- begin
- Byte1:=ord(copy(dta,28,1));
- Byte2:=ord(copy(dta,27,1));
- Byte3:=ord(copy(dta,29,1));
- Byte4:=ord(copy(dta,30,1));
- Size:=Byte1 shl 8+Byte2;
- if Size<0 then Size:=Size+65536.0; { adjust for negative values }
- Size:=(Byte3 shl 8+Byte4)*256.0+Size;
- FileSize:=Size;
- end; { filesize }
-
- function FileDate: str9; { decypher the File's Date Stamp }
- var Day,Month,Year: str2;
- Temp: integer;
- Byte1,Byte2: byte;
- begin
- Byte1:=ord(copy(dta,25,1));
- Byte2:=ord(copy(dta,26,1));
- str(Byte1 and 31:2,Day);
- Temp:=(Byte1 shr 5) and 7+(Byte2 and 1) shl 3;
- str(Temp:2,Month);
- str((Byte2 shr 1)+80:2,Year);
- if Day[1]=' ' then Day[1]:='0';
- if Year[1]=' ' then Year[1]:='0';
- FileDate:=Month+'-'+Day+'-'+Year;
- end; { filedate }
-
- function FileTime: str6; { decypher the File's Time Stamp }
- var Hour,Min: str2;
- Temp: integer;
- AmPm: char;
- Byte1,Byte2: byte;
- begin
- Byte1:=ord(copy(dta,23,1));
- Byte2:=ord(copy(dta,24,1));
- Temp:=(Byte1 shr 5) and 7+(Byte2 and 7) shl 3;
- str(Temp:2,Min);
- Temp:=Byte2 shr 3;
- if Temp<13 then AmPm:='a' else begin
- Temp:=Temp-12;
- AmPm:='p';
- end;
- if Temp = 0 then Temp := 12;
- str(Temp:2,Hour);
- if Min[1]=' ' then Min[1]:='0';
- FileTime:=Hour+':'+Min+AmPm;
- end; { filetime }
-
- procedure FillRecord(RecNo: byte); { fill List.[RecNo] with file info }
- begin
- with List[RecNo] do begin
- Name:=copy(Dta,31,13);
- i := Pos(chr(0),Name);
- if i <> 0 then Delete(Name,i,length(name));
- repeat if length(name)<13 then name:=name+' '; until length(name)=13;
- Attrib:=ord(copy(Dta,22,1));
- Size:=FileSize;
- Date:=FileDate;
- Time:=FileTime;
- dd:=FileDate;
- t:=FileTime;
- if (Name[1]<>'.') and (pos('.',Name)<>0) then begin { line up the }
- while pos('.',Name)<9 do insert(' ',Name,pos('.',Name)); { file ext. }
- Name[pos('.',Name)]:=' ';
- end;
- end;
- end; { fillrecord }
-
- procedure FillDirList;
- begin
- Total:=1;
- FillRecord(Total);
- repeat
- recpack.Ax:=$4f shl 8;
- MsDos(recpack);
- if (recpack.Ax<>18) and (recpack.Ax<>2) then begin
- Total:=Total+1;
- FillRecord(Total);
- end; { repeat filling until no more }
- until (recpack.flags and 1)<>0; { files are found }
- end; { filldirlist }
-
- begin { Directory }
- Total:=0;
- Dta:=' ';
- FileMask:=FileMask+#0;
- with recpack do begin { First, Set aside the DTA }
- Ax:=$1a shl 8; { or Data Transfer Area, }
- Ds:=Seg(Dta); Dx:=Ofs(Dta)+1; { call $1A then call $4E to }
- MsDos(recpack); { find the First Match. Set }
- Ax:=$4e shl 8; { set Cx to 23 to include all }
- Ds:=Seg(FileMask); Dx:=Ofs(FileMask)+1; { hidden files. Then up above }
- Cx:=23; { call $4F to find subsequent }
- MsDos(recpack); { matches, filling List. }
- if (flags and 1)=0 then FillDirList;
- end;
- end; { directory }
-
- begin
- FileMask := '';
- if ParamCount=1 then FileMask:=ParamStr(1);
- TextColor(White);
- if FileMask = '' then begin
- Write('Dir mask: ');
- readln(FileMask);
- end;
- Directory(FileMask,List,Total); { if available }
- for X:=1 to total do
- with List[X] do begin
- Normal:=True; Hidden:=False; System:=False; ReadOnly:=False; Archive:=False; Dircty:=False;
- if Attrib<>0 then Normal:=False;
- if (Attrib and 1)= 1 then ReadOnly:=True; { determine Attribute }
- if (Attrib and 2)= 2 then Hidden:= True; { Meanings }
- if (Attrib and 4)= 4 then System:= True;
- if (Attrib and 16)=16 then Dircty:= True;
- if (Attrib and 32)=32 then Archive:= True;
- Str(size:6:0,ss);
- line := Name+ss+' '+date+' '+time+' ';
- FastWrite(line,15,0,1);
- if Normal then FastWrite(N,15,0,1) else FastWrite(NN,15,0,1);
- if Archive then FastWrite(A,15,0,1) else FastWrite(AN,15,0,1);
- if ReadOnly then FastWrite(R,15,0,1) else FastWrite(RN,15,0,1);
- if Hidden then FastWrite(H,15,0,1) else FastWrite(HN,15,0,1);
- if System then FastWrite(S,15,0,1) else FastWrite(SN,15,0,1);
- if Dircty then FastWrite(D,15,0,1) else FastWrite(DN,15,0,1);
- writeln;
- end;
- writeln; writeln('Total Number of files: ',Total);
- end.