WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Listing Files from within Zip Files


Question:

How would I list files from within a Zip file without unzipping the file?

Can also find packed and unpacked size as well as date/time modified.

There are two integers that represent date and time, but I have not yet been able to convert to YMDHMS.

Answer:

#DefineFunction ListZipFiles(zipfile)
	initbb=binaryalloc(8)
	binaryreadex(initbb,0,zipfile,0,8)
	if binarypeek4(initbb,0)==67324752 then offset=0
	if binarypeek4(initbb,4)==67324752 then offset=4
	binaryfree(initbb)
	
	if !isdefined(offset)
	message("Error","Invalid Archive")
	exit
	endif
	list=""
	
	bb1=binaryalloc(30)
	
	while 1
	binaryreadex(bb1,0,zipfile,offset,30)
	;04 ZIPVER DW 0000 ;Version needed to extract 
	;06 ZIPGENFLG DW 0000 ;General purpose bit flag 
	;08 ZIPMTHD DW 0000 ;Compression method 
	;0A ZIPTIME DW 0000 ;Last mod file time (MS-DOS) 
	;0C ZIPDATE DW 0000 ;Last mod file date (MS-DOS) 
	;0E ZIPCRC HEX 00000000 ;CRC-32
	;12 ZIPSIZE HEX 00000000 ;Compressed size 
	;16 ZIPUNCMP HEX 00000000 ;Uncompressed size
	;1A ZIPFNLN DW 0000 ;Filename length
	;1C ZIPXTRALN DW 0000 ;Extra field length 
	;1E ZIPNAME DS ZIPFNLN ;filename 
	;-- ZIPXTRA DS ZIPXTRALN ;extra field 
	if binarypeek4(bb1,0)==33639248 then break
	ZIPVER=binarypeek2(bb1,4)
	ZIPGENFLG=binarypeek2(bb1,6)
	ZIPMTHD=binarypeek2(bb1,8)
	
	ZIPTIME=binarypeek2(bb1,10)
	ZIPDATE=binarypeek2(bb1,12)
	ZIPCRC=binarypeek4(bb1,14)
	ZIPSIZE=binarypeek4(bb1,18)
	ZIPUNCMP=binarypeek4(bb1,22)
	ZIPFNLN=binarypeek2(bb1,26)
	ZIPXTRALN=binarypeek2(bb1,28) 
	bb2=binaryalloc(ZIPFNLN+ZIPXTRALN)
	binaryreadex(bb2,0,zipfile,offset+30,ZIPFNLN+ZIPXTRALN)
	
	ZIPNAME=binarypeekstr(bb2,0,ZIPFNLN)
	
	list=iteminsert(ZIPNAME,-1,list,@tab)
	
	ZIPXTRA=binarypeekstr(bb2,ZIPFNLN,ZIPXTRALN)
	
	binaryfree(bb2)
	offset=offset+30+ZIPSIZE+ZIPFNLN+ZIPXTRALN
	endwhile
	return list
#EndFunction

zipfile="C:\Temp\Downloaded Zips\wwads34i.zip"
list = ListZipFiles(zipfile)
AskItemList(StrCat("Files in ",zipfile),list,@tab,@unsorted,@single) 

Article ID:   W15990
File Created: 2004:03:30:15:42:08
Last Updated: 2004:03:30:15:42:08