ฟอรั่ม PSsix

Would you like to react to this message? Create an account in a few clicks or log in to continue.

ฟอรั่มของบล็อก http://pssix.blogspot.com


3 posters

    ต้องการฟังชั่นแตกไฟล์ ZIP

    Quixotic
    Quixotic
    PSsix Member High Class
    PSsix Member High Class


    PSsix Program Coder
    จำนวนข้อความ : 91
    ความนิยม : 1
    เข้าร่วมเมื่อ : 29/03/2011

    ต้องการฟังชั่นแตกไฟล์ ZIP Empty ต้องการฟังชั่นแตกไฟล์ ZIP

    ตั้งหัวข้อ by Quixotic 12/05/11, 01:29 am

    คือผมลองค้นหาฟังชั่นแตกไฟล์ zip ดูแล้วแต่มันมีแต่ตัวที่ไม่ได้ดั่งใจอ่ะครับ

    ผมต้องการฟังชั่นที่แตกไฟล์ไปแล้วเลือกได้ว่าต้องให้ไฟล์ที่แตกไปชื่อไร

    ประมาณแบบนี้อ่ะครับ

    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 )

    ใครทำเป็นหรือมีเก็บไว้ ก็เอามาแบ่งผมมั่งนะครับ
    POS
    POS
    PSsix
    PSsix


    ต้องการฟังชั่นแตกไฟล์ ZIP Empty ต้องการฟังชั่นแตกไฟล์ ZIP Empty ต้องการฟังชั่นแตกไฟล์ ZIP Empty
    จำนวนข้อความ : 1152
    ความนิยม : 326
    เข้าร่วมเมื่อ : 19/07/2010

    ต้องการฟังชั่นแตกไฟล์ ZIP Empty Re: ต้องการฟังชั่นแตกไฟล์ ZIP

    ตั้งหัวข้อ by POS 12/05/11, 10:20 am

    Code:
    #include <Zip.au3>

    _Zip_Unzip(@ScriptDir&"\buttons_en.zip","find.gif", "C:\123",21)
    FileMove("C:\123\find.gif", "C:\123\aaa.gif")

    _Zip_Unzip(ตำแหน่งไฟล์.zip,ชื่อไฟล์ใน .zip ที่จะ unzip ออกมา, ตำแหน่งไดรฟ์และโฟลเดอร์ปลายทาง,21) ;21 เป็นรหัสกำหนดให้ เขียนทับไฟล์เดิม ไม่แสดงกล่องโปรเซส และตอบคำถามในการ unzip เป็นแบบ "Yes to All"



    ตัวอย่างด้านบนนี้เป็นการ unzip และ เปลี่ยนชื่อทีละไฟล์ ถ้าไฟล์จำนวนมาก็เปลี่ยนมาใช้ _Zip_UnzipAll แทน จากนั้นก็ใช้คำสั่ง _FileListToArray ดึงเอาชื่อไฟล์ทั้งหมดมาเปลี่ยนชื่อตามต้องการ

    ไฟล์ zip.au3 ดาวน์โหลดที่โฟสนี้ นำไปวางไว้ในโฟลเดอร์เดียวกับสคริปต์





    Attachments
    ต้องการฟังชั่นแตกไฟล์ ZIP AttachmentZip.zip
    Zip.au3
    You don't have permission to download attachments.
    (7 Kb) Downloaded 13 times
    Quixotic
    Quixotic
    PSsix Member High Class
    PSsix Member High Class


    PSsix Program Coder
    จำนวนข้อความ : 91
    ความนิยม : 1
    เข้าร่วมเมื่อ : 29/03/2011

    ต้องการฟังชั่นแตกไฟล์ ZIP Empty Re: ต้องการฟังชั่นแตกไฟล์ ZIP

    ตั้งหัวข้อ by Quixotic 12/05/11, 03:10 pm

    อ่า พอดีผมก็ใช้ตัวนี้อยู่ครับและมีปัญหากับตัวนี้มากมายเลย

    ตอนผมทดสอบเองมันไม่มีปัญหาอ่ะนะครับ

    แต่ผมส่งให้คนอื่นมันมักจะขึ้นเออเร่อ 3 4 5 ซึ่งผมก็ไปดูโค๊ด Error ของมันมาแล้ว

    แล้วก็ทำการแก้ไข พอแก้เสร็จก็เหมือนจะหาย แล้วก็มี Error อื่นขึ้นมาแทน

    ทั้งๆที่ผมมั่นใจว่าใช้ถูกหลักไม่ผิดผี

    อยากจะทราบว่า OS ที่ใช้มันมีผลกับการทำงานของสคริปไหมครับ

    Code:


                      _Zip_Unzip(@ScriptDir & "\test.zip","test.jpg", @ScriptDir & "\Halo")
                      If @error Then
                         MsgBox(0,"Error","Error : " & @error)
                         
                         Exit
                      EndIf

    Code:

    ;Error Code
    | 1 - zipfldr.dll does not exist
    ;                              | 2 - Library not installed
    ;                              | 3 - Not a full path
    ;                              | 4 - ZIP file / item path does not exist
    ;                              | 5 - Item not found in ZIP file
    ;                              | 6 - Failed to create destination (if necessary)
    ;                              | 7 - Failed to open destination
    ;                              | 8 - Failed to delete destination file / folder for overwriting
    ;                              | 9 - Destination exists and overwrite flag not set
    ;                              |10 - Failed to extract file
    POS
    POS
    PSsix
    PSsix


    ต้องการฟังชั่นแตกไฟล์ ZIP Empty ต้องการฟังชั่นแตกไฟล์ ZIP Empty ต้องการฟังชั่นแตกไฟล์ ZIP Empty
    จำนวนข้อความ : 1152
    ความนิยม : 326
    เข้าร่วมเมื่อ : 19/07/2010

    ต้องการฟังชั่นแตกไฟล์ ZIP Empty Re: ต้องการฟังชั่นแตกไฟล์ ZIP

    ตั้งหัวข้อ by POS 12/05/11, 08:33 pm

    ตามปกติไม่มีปัญหาครับ เพราะฟังก์ชันนี้เป็นการดึงเอาความสามารถใน zip ไฟล์ของวินโดวส์ออกมาใช้ (มีอยู่ในทุกเวอร์ชั่น xp vista 7)

    Error
    3 = ตำแหน่งไฟล์ไม่ถูกต้อง
    4 = ไฟล์ zip หรือตำแหน่งไฟล์ที่อยู่ในไฟล์ zip ไม่ถูกต้อง
    5 = ไฟล์ที่ต้องการ unzip ไม่มีอยู่ในไฟล์ zip

    จากที่แจ้งมาน่าจะเกิดจากการระบุตำแหน่งไม่ถูกต้องในไฟล์ zip (มีโฟลเดอร์ย่อยซ้อนอยู่ใน zipหรือพิมพ์ชื่อไฟล์และตำแหน่งไฟล์ไม่ถูก)
    Quixotic
    Quixotic
    PSsix Member High Class
    PSsix Member High Class


    PSsix Program Coder
    จำนวนข้อความ : 91
    ความนิยม : 1
    เข้าร่วมเมื่อ : 29/03/2011

    ต้องการฟังชั่นแตกไฟล์ ZIP Empty Re: ต้องการฟังชั่นแตกไฟล์ ZIP

    ตั้งหัวข้อ by Quixotic 13/05/11, 01:08 am

    ครับผม

    ผมจะพยายามพัฒนาต่อไป

    em234
    rolovely
    rolovely
    PSsix Member Super Class II
    PSsix Member Super Class II


    PSsix Game Coder
    จำนวนข้อความ : 193
    ความนิยม : 26
    เข้าร่วมเมื่อ : 15/10/2010
    อายุ : 35
    ที่อยู่ : THAILAND

    ต้องการฟังชั่นแตกไฟล์ ZIP Empty Re: ต้องการฟังชั่นแตกไฟล์ ZIP

    ตั้งหัวข้อ by rolovely 23/05/11, 01:42 am

    ให้ทำการตรวจที่อยู่จาก regedit เอาครับ

      เวลาขณะนี้ 02/05/24, 06:49 am