1. -- ************************************************************************
  2. -- Script:   ZIPLIST
  3. -- Version:  0.1
  4. -- Date:     2008-12-02
  5. --
  6. -- purpose:
  7. -- returns list of files found in ZIP archive
  8. --
  9. -- requirements:
  10. -- + Director 10 or older
  11. -- + a read/write xtra: fileIO xtra, BinFile xtra or BinaryIO xtra
  12. -- + a corresponding "interface script" from here:
  13. --   http://dasdeck.de/staff/valentin/lingo/binary_file_interface/
  14. --
  15. -- usage:
  16. -- put ziplist("c:\test.zip")
  17. -- ************************************************************************
  18. on ziplist fn
  19.   fp = fopen(fn, "rb")
  20.   fsize = fsize(fp)
  21.   fseek (fp, fsize-6)
  22.   data = fread(fp, 4)
  23.   pos = chartonum(data.char[1]) + 256*chartonum(data.char[2])+256*256*chartonum(data.char[3])+256*256*256*chartonum(data.char[4])
  24.   fseek (fp, pos)  
  25.   filelist = []
  26.   magic = "PK"&numtochar(1)&numtochar(2)
  27.   repeat while true
  28.     if fread(fp, 4)<>magic then exit repeat    
  29.     fseek(fp, 24, 1)
  30.     lenStr = fread(fp,2)
  31.     len = chartonum(lenStr.char[1]) + 256*chartonum(lenStr.char[2])
  32.     fseek(fp, 16, 1)
  33.     filelist.add(fread(fp, len))
  34.   end repeat
  35.   fclose(fp)
  36.   return filelist
  37. end
[raw code]