Jump to content

_FileListToArray, then error


Recommended Posts

Hi everyone,

I've got a bit of code that gets the file name of a zip file in a particular directory and tried to unzip it.  _FileListToArray should create an array and define $aArray[1] as the first file returned by the search.  But when I try to use $aArray[1] for anything, I get the error: "==> Array variable has incorrect number of subscripts or subscript dimension range exceeded."

Any thoughts?

If $osbit = "32" Then
    Local $aFileList = _FileListToArray($extract_dir, "*win32*")
    _ExtractZip($extract_dir & $aArray[1], $extract_dir)
ElseIf $osbit = "64" Then
    Local $aFileList = _FileListToArray($extract_dir, "*amd*")
    _ExtractZip($extract_dir & $aArray[1], $extract_dir)
EndIf

Thanks.

Link to comment
Share on other sites

  • Moderators

How about doing an _ArrayDisplay to see what value sits at $aArray[1]? Or posting your entire code, along with the _ExtractZIp function, so we can test?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

_ArrayDisplay does seem to work fine.  Here's the entire script (obviously file paths will mean nothing):

#include <GuiEdit.au3>
#include <GuiListBox.au3>
#include <GuiComboBox.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <Array.au3>

AutoItSetOption ( "SendKeyDelay" , 30 )
AutoItSetOption ( "TrayIconDebug", 1 )
Opt("WinTitleMatchMode", 2)

; GET BITNESS OF OS (CRUDE METHOD)
If FileExists("C:\Program Files (x86)") Then
    Local $osbit = "64"
Else
    Local $osbit = "32"
EndIf

Local $aArray[0], $aArray[1]

Sleep(1000)

; COPY PATCH ZIP FILE
FileCopy("\\chi413071\Ship\HSF11.1.2.4\11_1_2_4_000_3031\BuildPatch.zip", "C:\Oracle\Middleware\EPMSystem11R1\opatch\", $FC_OVERWRITE)

MsgBox(0, "", "")
Sleep(1000)
Local $opatch_dir = "C:\Oracle\Middleware\EPMSystem11R1\opatch\"
Local $extract_dir = "C:\Oracle\Middleware\EPMSystem11R1\opatch\Extracted"
DirCreate($extract_dir) ; to extract to
_ExtractZip($opatch_dir & "BuildPatch.zip", $extract_dir)
If $osbit = "32" Then
    Local $aFileList = _FileListToArray($extract_dir, "*win32*")
    _ExtractZip($extract_dir & $aArray[1], $extract_dir)
ElseIf $osbit = "64" Then
    Local $aFileList = _FileListToArray($extract_dir, "*amd*")
    _ExtractZip($extract_dir & $aArray[1], $extract_dir)
EndIf

Sleep(5000)

Exit

; #FUNCTION# ;===============================================================================
;
; Name...........: _ExtractZip
; Description ...: Extracts file/folder from ZIP compressed file
; Syntax.........: _ExtractZip($sZipFile, $sDestinationFolder)
; Parameters ....: $sZipFile - full path to the ZIP file to process
;                  $sDestinationFolder - folder to extract to. Will be created if it does not exsist 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, modifyed by corgano
;
;==========================================================================================
Func _ExtractZip($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
Link to comment
Share on other sites

In your code, something is strange :

Local $aArray[0], $aArray[1]  => you are declaring an array two times, and you don't use it after, so you can delete this line

  Local $aFileList = _FileListToArray($extract_dir, "*win32*")
_ExtractZip($extract_dir & $aArray[1], $extract_dir)
    => $aArray[1] does not exists, because you have declared $aArray with just one element (row 0). You may want to use $aFileList, which is the result of _FileListToArray

Replace $aArray[1] by $aFileList[1], but I don't understand which file you want to extract. Instead of $aFileList[1], you should use the file name (if you know if, of course)

Link to comment
Share on other sites

Universalist, I was in the process of updating this thread when you posted.  Yes, I need to use $aFileList since that is what is capturing the return of _FileListToArray!  I was just relying too much on examples, and this was my first time using an array.  Thank you.

The reason I need to do this is that the name of the zip file to extract will never be the same, as it contains a build number that increments with each build.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...