| torels |
| | Ciao a tutti Voglio presentarvi il mio udf per zippare i files sul forum inglese ha avuto quasi 1000 downloads Spero torni utile a qualcuno Queste sono le funzioni (nonche' user CallTip entries) CODICE _Zip_Create($FileName) Create Zip File. Required #include <Zip.au3> _Zip_AddFile($ZipFile, $File2Add, [$flag]) Add file to Zip Archive. Required #include <Zip.au3> _Zip_AddFolder($ZipFile, $Folder, [$flag]) Add folder to Zip Archive. Required #include <Zip.au3> _Zip_AddFolderContents($ZipFile, $Folder, [$flag]) Add folder's content to Zip Archive. Required #include <Zip.au3> _Zip_UnzipAll($ZipFile, $DestPath, [$flag]) Extract all files from Zip Archive. Required #include <Zip.au3> _Zip_Unzip($ZipFile,$FileName, $DestPath, [$flag]) Extract file from Zip Archive. Required #include <Zip.au3> _Zip_Count($ZipFile) Count items in zip. Required #include <Zip.au3> _Zip_List($ZipFile) List items in zip. Required #include <Zip.au3> _Zip_Search($ZipFile, $SearchString) Search a File in the Zip Archive. Required #include <Zip.au3> _Zip_SearchInFile($ZipFile, $SearchString) Search In each File of the Zip Archive. Required #include <Zip.au3> ecco il codice CODICE ;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <array.au3> ; ------------------------------------------------------------------------------ ; ; AutoIt Version: 3.2 ; Language: English ; Description: ZIP Functions. ; Author: torels_ ; ; ------------------------------------------------------------------------------ ;=============================================================================== ; ; Function Name: _Zip_Create() ; Description: Create Empty ZIP file. ; Parameter(s): $hFilename - Complete path to zip file that will be created ; Requirement(s): none. ; Return Value(s): On Success - Returns the Zip file path (to be used as a handle - even though it's not necessary) ; On Failure - @error = 1 (file could not be created) ; Author(s): torels_ ; ;=============================================================================== Func _Zip_Create($hFilename) $hFp = FileOpen($hFilename, 26) $sString = Chr(80) & Chr(75) & Chr(5) & Chr(6) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) FileWrite($hFp, $sString) FileClose($hFp) If Not FileExists($hFilename) Then Return SetError(1, 0, 0) Else Return $hFilename EndIf EndFunc ;==>_Zip_Create
;=============================================================================== ; ; Function Name: _Zip_AddFile() ; Description: Add a file to a ZIP Archieve. ; Parameter(s): $hZipFile - Complete path to zip file that will be created (or handle if existant) ; $hFile2Add - Complete path to the file that will be added ; $flag = 1 ; - 0 ProgressBox ; - 1 no progress box ; Requirement(s): none. ; Return Value(s): On Success - 0 ; On Failure - sets @error 1~3 ; @error = 1 no Zip file ; @error = 2 no dll ; @error = 3 dll isn't registered ; On Failure - Returns False ; Author(s): torels_ ; Notes: The return values will be given once the compressing process is ultimated... it takes some time with big files ; ;=============================================================================== Func _Zip_AddFile($hZipFile, $hFile2Add, $flag = 4) Local $DLLChk = _Zip_DllChk() Local $files = _Zip_Count($hZipFile) If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0);no dll If Not FileExists($hZipFile) Then Return SetError(1, 0, 0) ;no zip file $oApp = ObjCreate("Shell.Application") $copy = $oApp.NameSpace($hZipFile).CopyHere($hFile2Add) ;WinSetState"[CLASS:SysAnimate32; INSTANCE:1]" "#32770" While 1 If _Zip_Count($hZipFile) = ($files+1) Then ExitLoop WEnd Return SetError(0,0,1) EndFunc ;==>_Zip_AddFile
;=============================================================================== ; ; Function Name: _Zip_AddFolder() ; Description: Add a folder to a ZIP Archieve. ; Parameter(s): $hZipFile - Complete path to zip file that will be created (or handle if existant) ; $hFolder - Complete path to the folder that will be added (possibly including "\" at the end) ; $flag = 4 ; - 4 no progress box ; - 8 file name changed if already exists ; - 16 respond "yes to all" for any dialog box displayed ; - 64 preservw undo information, if possible ; - 256 progress dialogbox without file names on it ; - 512 Do not confirm the creation of a directory if the operation requires one to be created ; - 1024 Do not display a user interface if an error occours ; - 4096 Don't operate recursively in subdirectories but just in the local directory ; Requirement(s): none. ; Return Value(s): On Success - 0 ; On Failure - sets @error 1~3 ; @error = 1 no Zip file ; @error = 2 no dll ; @error = 3 dll isn't registered ; Author(s): torels_ ; Notes: The return values will be given once the compressing process is ultimated... it takes some time with big files ; ;=============================================================================== Func _Zip_AddFolder($hZipFile, $hFolder, $flag = 4) Local $DLLChk = _Zip_DllChk() If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0);no dll If Not FileExists($hZipFile) Then Return SetError(1, 0, 0) ;no zip file If StringRight($hFolder, 1) <> "\" Then $hFolder &= "\" $files = _Zip_Count($hZipFile) $oApp = ObjCreate("Shell.Application") $oCopy = $oApp.NameSpace($hZipFile).CopyHere($oApp.Namespace($hFolder), $flag)
While 1 If _Zip_Count($hZipFile) = ($files+1) Then ExitLoop WEnd Return SetError(0,0,1) EndFunc ;==>_Zip_AddFolder
;=============================================================================== ; ; Function Name: _Zip_AddFolderContents() ; Description: Add a folder to a ZIP Archieve. ; Parameter(s): $hZipFile - Complete path to zip file that will be created (or handle if existant) ; $hFolder - Complete path to the folder that will be added (possibly including "\" at the end) ; $flag = 4 ; - 4 no progress box ; - 8 file name changed if already exists ; - 16 respond "yes to all" for any dialog box displayed ; - 64 preservw undo information, if possible ; - 256 progress dialogbox without file names on it ; - 512 Do not confirm the creation of a directory if the operation requires one to be created ; - 1024 Do not display a user interface if an error occours ; - 4096 Don't operate recursively in subdirectories but just in the local directory ; Requirement(s): none. ; Return Value(s): On Success - 0 ; On Failure - sets @error 1~3 ; @error = 1 no Zip file ; @error = 2 no dll ; @error = 3 dll isn't registered ; Author(s): torels_ ; Notes: The return values will be given once the compressing process is ultimated... it takes some time with big files ; ;=============================================================================== Func _Zip_AddFolderContents($hZipFile, $hFolder, $flag = 4) Local $DLLChk = _Zip_DllChk() If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0);no dll If Not FileExists($hZipFile) Then Return SetError(1, 0, 0) ;no zip file If StringRight($hFolder, 1) <> "\" Then $hFolder &= "\" $files = _Zip_Count($hZipFile) $oApp = ObjCreate("Shell.Application") $oFolder = $oApp.NameSpace($hFolder) $oCopy = $oApp.NameSpace($hZipFile).CopyHere($oFolder.Items, $flag) $oFC = $oApp.NameSpace($hFolder).items.count
While 1 If _Zip_Count($hZipFile) = ($files+$oFC) Then ExitLoop WEnd Return SetError(0,0,1) EndFunc ;==>_Zip_AddFolderContents
;=============================================================================== ; ; Function Name: _Zip_UnzipAll() ; Description: Extract all files contained in a ZIP Archieve. ; Parameter(s): $hZipFile - Complete path to zip file that will be created (or handle if existant) ; $hDestPath - Complete path to where the files will be extracted ; $flag = 4 ; - 4 no progress box ; - 8 file name changed if already exists ; - 16 respond "yes to all" for any dialog box displayed ; - 64 preservw undo information, if possible ; - 256 progress dialogbox without file names on it ; - 512 Do not confirm the creation of a directory if the operation requires one to be created ; - 1024 Do not display a user interface if an error occours ; - 4096 Don't operate recursively in subdirectories but just in the local directory ; Requirement(s): none. ; Return Value(s): On Success - 0 ; On Failure - sets @error 1~3 ; @error = 1 no Zip file ; @error = 2 no dll ; @error = 3 dll isn't registered ; Author(s): torels_ ; Notes: The return values will be given once the extracting process is ultimated... it takes some time with big files ; ;=============================================================================== Func _Zip_UnzipAll($hZipFile, $hDestPath, $flag = 4) Local $DLLChk = _Zip_DllChk() If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0);no dll If Not FileExists($hZipFile) Then Return SetError(2, 0, 0) ;no zip file If Not FileExists($hDestPath) Then DirCreate($hDestPath) Local $aArray[1] $oApp = ObjCreate("Shell.Application") $oApp.Namespace($hDestPath).CopyHere($oApp.Namespace($hZipFile).Items, $flag) For $item In $oApp.Namespace($hZipFile).Items _ArrayAdd($aArray, $item) Next While 1 Sleep(500) If FileExists($hDestPath & "\" & $aArray[UBound($aArray) - 1]) Then Return SetError(0, 0, 1) ExitLoop WEnd EndFunc ;==>_Zip_UnzipAll
;=============================================================================== ; ; Function Name: _Zip_Unzip() ; Description: Extract a single file contained in a ZIP Archieve. ; Parameter(s): $hZipFile - Complete path to zip file that will be created (or handle if existant) ; $hFilename - Name of the element in the zip archive ex. "hello_world.txt" ; $hDestPath - Complete path to where the files will be extracted ; $flag = 4 ; - 4 no progress box ; - 8 file name changed if already exists ; - 16 respond "yes to all" for any dialog box displayed ; - 64 preservw undo information, if possible ; - 256 progress dialogbox without file names on it ; - 512 Do not confirm the creation of a directory if the operation requires one to be created ; - 1024 Do not display a user interface if an error occours ; - 4096 Don't operate recursively in subdirectories but just in the local directory ; Requirement(s): none. ; Return Value(s): On Success - 0 ; On Failure - sets @error 1~3 ; @error = 1 no Zip file ; @error = 2 no dll ; @error = 3 dll isn't registered ; Author(s): torels_ ; Notes: The return values will be given once the extracting process is ultimated... it takes some time with big files ; ;=============================================================================== Func _Zip_Unzip($hZipFile, $hFilename, $hDestPath, $flag = 4) Local $DLLChk = _Zip_DllChk() If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0) ;no dll If Not FileExists($hZipFile) Then Return SetError(1, 0, 0) ;no zip file If Not FileExists($hDestPath) Then DirCreate($hDestPath) $oApp = ObjCreate("Shell.Application") $hFolderitem = $oApp.NameSpace($hZipFile).Parsename($hFilename) $oApp.NameSpace($hDestPath).Copyhere($hFolderitem, $flag) While 1 Sleep(500) If FileExists($hDestPath & "\" & $hFilename) Then return SetError(0, 0, 1) ExitLoop EndIf WEnd EndFunc ;==>_Zip_Unzip
;=============================================================================== ; ; Function Name: _Zip_Count() ; Description: Count files contained in a ZIP Archieve. ; Parameter(s): $hZipFile - Complete path to zip file that will be created (or handle if existant) ; Requirement(s): none. ; Return Value(s): On Success - 0 ; On Failure - sets @error 1~3 ; @error = 1 no Zip file ; @error = 2 no dll ; @error = 3 dll isn't registered ; Author(s): torels_ ; ;=============================================================================== Func _Zip_Count($hZipFile) Local $DLLChk = _Zip_DllChk() If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0) ;no dll If Not FileExists($hZipFile) Then Return SetError(1, 0, 0) ;no zip file $items = _Zip_List($hZipFile) Return UBound($items) - 1 EndFunc ;==>_Zip_Count
;=============================================================================== ; ; Function Name: _Zip_Count() ; Description: Returns a collection of all the files contained in a ZIP Archieve. ; Parameter(s): $hZipFile - Complete path to zip file that will be created (or handle if existant) ; Requirement(s): none. ; Return Value(s): On Success - 0 ; On Failure - sets @error 1~3 ; @error = 1 no Zip file ; @error = 2 no dll ; @error = 3 dll isn't registered ; Author(s): torels_ ; ;=============================================================================== Func _Zip_List($hZipFile) local $aArray[1] Local $DLLChk = _Zip_DllChk() If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0) ;no dll If Not FileExists($hZipFile) Then Return SetError(1, 0, 0) ;no zip file $oApp = ObjCreate("Shell.Application") $hList = $oApp.Namespace($hZipFile).Items For $item in $hList _ArrayAdd($aArray,$item.name) Next $aArray[0] = UBound($aArray) - 1 Return $aArray EndFunc ;==>_Zip_List
;=============================================================================== ; ; Function Name: _Zip_Search() ; Description: Search files in a ZIP Archive. ; Parameter(s): $hZipFile - Complete path to zip file that will be created (or handle if existant) ; $sSearchString - name of the file to be searched ; Requirement(s): none. ; Return Value(s): On Success - 0 ; On Failure - sets @error 1 (no file found) ; Author(s): torels_ ; Notes: none ; ;=============================================================================== Func _Zip_Search($hZipFile, $sSearchString) local $aArray $list = _Zip_List($hZipFile) for $i = 0 to UBound($list) - 1 if StringInStr($list[$i],$sSearchstring) > 0 Then _ArrayAdd($aArray, $list[$i]) EndIf Next if UBound($aArray) - 1 = 0 Then Return SetError(1,0,0) Else Return $aArray EndIf EndFunc ;==> _Zip_Search
;=============================================================================== ; ; Function Name: _Zip_SearchInFile() ; Description: Search files in a ZIP Archive. ; Parameter(s): $hZipFile - Complete path to zip file that will be created (or handle if existant) ; $sSearchString - name of the file to be searched ; Requirement(s): none. ; Return Value(s): On Success - 0 ; On Failure - sets @error 1 (no file found) ; Author(s): torels_ ; Notes: none ; ;=============================================================================== Func _Zip_SearchInFile($hZipFile, $sSearchString) local $aArray $list = _Zip_List($hZipFile) for $i = 1 to UBound($list) - 1 _Zip_Unzip($hZipFile, $list[$i], @TempDir & "\tmp_zip.file") FileRead(@TempDir & "\tmp_zip.file") if StringInStr($read,$sSearchstring) > 0 Then _ArrayAdd($aArray, $list[$i]) EndIf Next if UBound($aArray) - 1 = 0 Then Return SetError(1,0,1) Else Return $aArray EndIf EndFunc ;==> _Zip_Search
;=============================================================================== ; ; Function Name: _Zip_DllChk() ; Description: Internal error handler. ; Parameter(s): none. ; Requirement(s): none. ; Return Value(s): Failure - @extended = 1 ; Author(s): smashley ; ;=============================================================================== Func _Zip_DllChk() If Not FileExists(@SystemDir & "\zipfldr.dll") Then Return 2 If Not RegRead("HKEY_CLASSES_ROOT\CLSID\{E88DCCE0-B7B3-11d1-A9F0-00AA0060FA31}", "") Then Return 3 Return 0 EndFunc ;==>_Zip_DllChk
| | |
| |
|