คือผมลองค้นหาฟังชั่นแตกไฟล์ zip ดูแล้วแต่มันมีแต่ตัวที่ไม่ได้ดั่งใจอ่ะครับ
ผมต้องการฟังชั่นที่แตกไฟล์ไปแล้วเลือกได้ว่าต้องให้ไฟล์ที่แตกไปชื่อไร
ประมาณแบบนี้อ่ะครับ
ZipExtract(ชื่อไฟล์ .zip,โฟลเด้อหรือชื่อไฟล์ปลายทาง)
มันจะมีแค่ 2-3 พารามีเตอร์อ่ะครับ
ที่พบขุดมาได้ก็
กับ Include Zip แล้วก็ตัวที่ใช้ dll
แต่ผมอยากได้แบบที่ แตกไฟล์ไปแล้วเลือกได้ว่า จะแตกไปที่ไหน ชื่อไฟล์อะไร (ชื่อไฟล์ที่ต้องการหลังแตกไปแล้ว)
เพราะเมื่อก่อนผมเคยขุดเจอ แต่มันอยู่ในสคริปตัวเก่าผม ซึ่งมันลบตัวเองไปแล้ว ( เป็นผลจากการทดลองสคริป Autoupdate )
ใครทำเป็นหรือมีเก็บไว้ ก็เอามาแบ่งผมมั่งนะครับ
ผมต้องการฟังชั่นที่แตกไฟล์ไปแล้วเลือกได้ว่าต้องให้ไฟล์ที่แตกไปชื่อไร
ประมาณแบบนี้อ่ะครับ
ZipExtract(ชื่อไฟล์ .zip,โฟลเด้อหรือชื่อไฟล์ปลายทาง)
มันจะมีแค่ 2-3 พารามีเตอร์อ่ะครับ
ที่พบขุดมาได้ก็
- Code:
Func _ExtractZip2($sZipFile, $sDestinationFolder, $sFolderStructure = "")
Local $i
Do
$i += 1
$sTempZipFolder = @TempDir & "\Temporary Directory " & $i & " for " & StringRegExpReplace($sZipFile, ".*\\", "")
Until Not FileExists($sTempZipFolder) ; this folder will be created during extraction
Local $oShell = ObjCreate("Shell.Application")
If Not IsObj($oShell) Then
Return SetError(1, 0, 0) ; highly unlikely but could happen
EndIf
Local $oDestinationFolder = $oShell.NameSpace($sDestinationFolder)
If Not IsObj($oDestinationFolder) Then
DirCreate($sDestinationFolder)
;~ Return SetError(2, 0, 0) ; unavailable destionation location
EndIf
Local $oOriginFolder = $oShell.NameSpace($sZipFile & "\" & $sFolderStructure) ; FolderStructure is overstatement because of the available depth
If Not IsObj($oOriginFolder) Then
Return SetError(3, 0, 0) ; unavailable location
EndIf
Local $oOriginFile = $oOriginFolder.Items();get all items
If Not IsObj($oOriginFile) Then
Return SetError(4, 0, 0) ; no such file in ZIP file
EndIf
; copy content of origin to destination
$oDestinationFolder.CopyHere($oOriginFile, 20) ; 20 means 4 and 16, replaces files if asked
DirRemove($sTempZipFolder, 1) ; clean temp dir
Return 1 ; All OK!
EndFunc
Func _ExtractZip1($sZipFile, $sFolderStructure, $sFile, $sDestinationFolder)
Local $i
Do
$i += 1
$sTempZipFolder = @TempDir & "\Temporary Directory " & $i & " for " & StringRegExpReplace($sZipFile, ".*\\", "")
Until Not FileExists($sTempZipFolder) ; this folder will be created during extraction
Local $oShell = ObjCreate("Shell.Application")
If Not IsObj($oShell) Then Return SetError(1)
Local $oDestinationFolder = $oShell.NameSpace($sDestinationFolder)
If Not IsObj($oDestinationFolder) Then Return SetError(2) ; unavailable destionation location
Local $oOriginFolder = $oShell.NameSpace($sZipFile & "\" & $sFolderStructure) ; FolderStructure is overstatement because of the available depth
If Not IsObj($oOriginFolder) Then Return SetError(3) ; unavailable location
;Local $oOriginFile = $oOriginFolder.Items.Item($sFile)
Local $oOriginFile = $oOriginFolder.ParseName($sFile)
If Not IsObj($oOriginFile) Then Return SetError(4) ; no such file in ZIP file
; copy content of origin to destination
$oDestinationFolder.CopyHere($oOriginFile, 4) ; 4 means "do not display a progress dialog box"
DirRemove($sTempZipFolder, 1) ; clean temp dir if needed
Return 1 ; All OK!
EndFunc
#cs
DirCreate(@DesktopDir & "\Extracted") ; to extract to
_ExtractZip(@DesktopDir & "\YourZipFile.zip", "SomeFolderWithinOrNothing", "FileOrFolderToExtract.extensionIfEny", @DesktopDir & "\Extracted")
ConsoleWrite(@error & @CRLF)
#ce
; #FUNCTION# ;===============================================================================
;
; Name...........: _ExtractZip
; Description ...: Extracts file/folder from ZIP compressed file
; Syntax.........: _ExtractZip($sZipFile, $sFolderStructure, $sFile, $sDestinationFolder)
; Parameters ....: $sZipFile - full path to the ZIP file to process
; $sFolderStructure - 'path' to the file/folder to extract inside ZIP file
; $sFile - file/folder to extract
; $sDestinationFolder - folder to extract to. Must exist.
; Return values .: Success - Returns 1
; - Sets @error to 0
; Failure - Returns 0 sets @error:
; |1 - Shell Object creation failure
; |2 - Destination folder is unavailable
; |3 - Structure within ZIP file is wrong
; |4 - Specified file/folder to extract not existing
; Author ........: trancexx
;
;==========================================================================================
Func _ExtractZip($sZipFile, $sFolderStructure, $sFile, $sDestinationFolder)
Local $i
Do
$i += 1
$sTempZipFolder = @TempDir & "\Temporary Directory " & $i & " for " & StringRegExpReplace($sZipFile, ".*\\", "")
Until Not FileExists($sTempZipFolder) ; this folder will be created during extraction
Local $oShell = ObjCreate("Shell.Application")
If Not IsObj($oShell) Then
Return SetError(1, 0, 0) ; highly unlikely but could happen
EndIf
Local $oDestinationFolder = $oShell.NameSpace($sDestinationFolder)
If Not IsObj($oDestinationFolder) Then
Return SetError(2, 0, 0) ; unavailable destionation location
EndIf
Local $oOriginFolder = $oShell.NameSpace($sZipFile & "\" & $sFolderStructure) ; FolderStructure is overstatement because of the available depth
If Not IsObj($oOriginFolder) Then
Return SetError(3, 0, 0) ; unavailable location
EndIf
;Local $oOriginFile = $oOriginFolder.Items.Item($sFile)
Local $oOriginFile = $oOriginFolder.ParseName($sFile)
If Not IsObj($oOriginFile) Then
Return SetError(4, 0, 0) ; no such file in ZIP file
EndIf
; copy content of origin to destination
$oDestinationFolder.CopyHere($oOriginFile, 4) ; 4 means "do not display a progress dialog box", but apparently doesn't work
DirRemove($sTempZipFolder, 1) ; clean temp dir
Return 1 ; All OK!
EndFunc
กับ Include Zip แล้วก็ตัวที่ใช้ dll
แต่ผมอยากได้แบบที่ แตกไฟล์ไปแล้วเลือกได้ว่า จะแตกไปที่ไหน ชื่อไฟล์อะไร (ชื่อไฟล์ที่ต้องการหลังแตกไปแล้ว)
เพราะเมื่อก่อนผมเคยขุดเจอ แต่มันอยู่ในสคริปตัวเก่าผม ซึ่งมันลบตัวเองไปแล้ว ( เป็นผลจากการทดลองสคริป Autoupdate )
ใครทำเป็นหรือมีเก็บไว้ ก็เอามาแบ่งผมมั่งนะครับ