* ZIPREAD.PRG * * Author: Lee A. Flier 05/05/93 * * Written in FoxPro 2.5 for DOS * * ZIPREAD(zipfile) will read a ZIP file and list the names of the files in * it. This is useful for checking archived files which you are tracking * in a database. Only the file names in the ZIP are returned; no file * sizes, dates or compression ratios, although these could probably be * added if someone could figure out which bytes referred to them! * * It works similarly to ADIR() in that it creates an array containing * the file names, and returns the number of files in the ZIP file. * If the file does not exist, ZIPREAD returns -1. If the file name * parameter was not given, it returns -2. If the file does not appear * to be a valid ZIP file, -3 is returned. * * The array ZIPFILES must be declared in the calling program; it can * have only 1 element since it is re-declared within the function. * * This function appears to work on any file created with PKZIP version * 2.0 or later; I can't guarantee the results with older ZIP files. parameters filename zipfil=fopen(filename) if zipfil <= 0 && file not found or parameter not given return zipfil && so return the error message endif iszip=fread(zipfil,3) if iszip <> 'PK'+chr(3) && first characters in a valid ZIP file return -3 endif * The 14th byte from the end of the file contains the number of * files. Create an array sized appropriately. =fseek(zipfil,-14,2) znum=asc(fread(zipfil,1)) if znum=0 =fclose(zipfil) return -3 endif =fseek(zipfil,-22,2) iszip=fread(zipfil,2) && check for invalid file if iszip <> 'PK' =fclose(zipfil) return -3 endif declare zipfiles[znum] =fseek(zipfil,-23,2) && move pointer to end of last filename * Read backwards through the ZIP file, storing each file name * to an array element for x=znum to 1 step -1 store '' to curr_file && the current file name being read z=fread(zipfil,1) do while z <> chr(0) curr_file=z+curr_file =fseek(zipfil,-2,1) z=fread(zipfil,1) enddo zipfiles[x] = curr_file =fseek(zipfil,-46,1) iszip=fread(zipfil,2) && check for invalid file if iszip <> 'PK' =fclose(zipfil) return -3 endif =fseek(zipfil,-3,1) endfor =fclose(zipfil) return znum