ZIP / UnZip simple
Posted: Sat Apr 04, 2020 3:56 am
hi,
i know HMG have COMPRESS and there also other Way e.g. 7ZIP
i like to show what is "behind" xCommand on Sample how to ZIP
Windows have build-in ZIP Support since XP and it is easy to use it
1.) create file and write "Header"
2.) create "Shell.Application" Object and "access ZIP" as virtual Folder
3.) use COPYHERE() to "stream" file to virtual ZIP Folder
while COPYHERE() work as own Thread you have to wait until finish before next.
4.) clean up COM Connection
---
more simple to un-zip ( Xbase++ Code )
i know HMG have COMPRESS and there also other Way e.g. 7ZIP
i like to show what is "behind" xCommand on Sample how to ZIP
Windows have build-in ZIP Support since XP and it is easy to use it
1.) create file and write "Header"
Code: Select all
LOCAL aHead := {80,75,5,6,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
// create ZIP and write Header
//
nHandle := FCreate( cZipFile, FC_NORMAL )
iMax := LEN(aHead)
FOR i := 1 TO iMax
FWrite( nHandle, CHR( aHead[i]) )
NEXT
FClose( nHandle )Code: Select all
// create COM Object
//
oShell := CreateObject("Shell.Application")
oZIP := oShell:NameSpace(cZipFile)
Code: Select all
FOR i := 1 TO nFiles
cFile := aFiles[i]
oZIP:CopyHere(cFile,xFlag) // copy one file
// wait until all file are written
//
xCount := 0
DO WHILE .T.
nCount := oZIP:items():Count()
IF nCount >= i
EXIT
ENDIF
SLEEP(10)
xCount++
IF xCount > 50
EXIT
ENDIF
ENDDO
NEXT
4.) clean up COM Connection
Code: Select all
oZIP := NIL
oShell := NILmore simple to un-zip ( Xbase++ Code )
Code: Select all
FUNCTION Unzip(cZipFile, cDestFolder)
LOCAL oShell, oZIP, oNameDest
oShell := CreateObject("Shell.Application")
oZIP := oShell:NameSpace(cZipFile)
oNameDest := oShell:NameSpace(cDestFolder)
oNameDest:CopyHere(oZIP:items(), 0x10)
oShell:destroy() // HMG -> oShell := NIL
RETURN NIL