home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 24.18 Zipdir()
- Author: Joe Booth
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
- //───── NOTE: must compile with the /N option!
-
- #include "FILEIO.CH"
-
- function zipdir(zip_file)
- LOCAL zip := fopen(zip_file,FO_READ), tmp :=space(4)
- LOCAL method,orig_date,fn_date,comp_size,uncomp
- LOCAL fn_size,extra,junk,_array:={},file_name
- while .t.
- tmp = space(4)
- if fread(zip,@tmp,4) <> 4 && End of file
- exit
- endif
- if tmp = "PK"+chr(1)+chr(2) && Central dir
- exit
- elseif tmp <> "PK"+chr(3)+chr(4)
- exit
- endif
- tmp := space(26)
- fread(zip,@tmp,26)
- method := bin2i(substr(tmp,5,2))
- orig_date := bin2i(substr(tmp,9,2))
- fn_date := Dos_date(orig_date)
- comp_size := bin2l(substr(tmp,15,4))
- uncomp := bin2l(substr(tmp,19,4))
- fn_size := bin2i(substr(tmp,23,2))
- extra := bin2i(substr(tmp,25,2))
- file_name := freadstr(zip,fn_size)
- tmp := space(extra)
- junk := if(extra=0,"",fread(zip,@tmp,extra))
- fseek(zip,comp_size,1)
- aadd(_array,{file_name,comp_size,uncomp,fn_date})
- enddo
- fclose(zip)
- return _array
-
-
- function dos_date(_datestamp)
- local temp :=dec2bin(_datestamp),yy,mm,dd
- yy := bin2dec(substr(temp,1,7)) +1980
- mm := bin2dec(substr(temp,8,4))
- dd := bin2dec(substr(temp,12,5))
- return ctod(str(mm,2)+"/"+str(dd,2)+"/"+str(yy,4))
-
-
- function Bin2dec(_string)
- local retval :=0 ,k
- for k=1 to len(_string)
- retval = If(Substr(_string,k,1)="0",0,1)+retval+retval
- next
- return retval
-
-
- function Dec2bin(_number)
- local tmp := _number,retval:="",remd,quot
- while .T.
- quot := int(tmp/2)
- remd := abs(tmp)-2*abs(quot)
- retval:= Substr("01",remd+1,1)+retval
- if quot= 0
- exit
- endif
- tmp := quot
- enddo
- while len(retval)<16
- retval="0"+retval
- enddo
- return retval
-
- // end of file CHP2418.PRG
-