Jump to content
Sign in to follow this  
Silverlode

_FileListToArray, then error

Recommended Posts

Silverlode

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.

Share this post


Link to post
Share on other sites
JLogan3o13

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?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Silverlode

_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

Share this post


Link to post
Share on other sites
jguinch

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)

Share this post


Link to post
Share on other sites
Silverlode

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.

Share this post


Link to post
Share on other sites
Silverlode

Duh...my apologies.  And thanks again.

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • vati1011
      By vati1011
      Hey, guys.
      Currently, I'm using Opencv UDF and i'm  encountering issues with DLLOPEN(). it is failing and returning -1
      But, I cannot figure out why it is failing.
      I need help from people.
      I'm running windows 10 32bit.
      This's my code.
      #RequireAdmin $fileopen = DllOpen("opencv_core2413.dll") MsgBox(0,"Result",$fileopen) Example.au3opencv_core2413.dll
    • Skeletor
      By Skeletor
      Hi Virtual People,
      My array works perfectly fine. However, what is the best practice if the line in the array doesn't have the correct amount of columns and if I can add a placeholder?

       
      For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") Next  
    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
    • Skeletor
      By Skeletor
      Hi All,

      I would like to know how you would take a FileLineRead and insert it into an array which then inserts it into Excel?
      One thing to know is the files content is broken up, so I only use half of the content within $FileRead1.
      So its imperative that the $value1, $value2, etc variables be used. 
      Code below:
      $FileRead1 = FileReadLine("C:\temp\sample.txt",1) For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value4, "D1") Next  
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to write a script that moves copies excel cells into an array. I'll than manipulate the values and send array into another program. 
      I don't want range to be specific to a workbook, or sheet, or set of cells.
      I want user to be able to highlight desired cells and to copy either normally ("Ctrl+C") or by a hotkey ("Alt+C"). 
      Could someone help me with this?
      Thank you,
      I've tried to write the framework: (edited)
      #include <MsgBoxConstants.au3> #include <Array.au3> #include <Excel.au3> HotKeySet("!v", "Pastedata") While True Sleep(1000) WEnd func Makearray() local $bArray ;User has cells already copied ;Convert clipboard into an array ;I don;t know how excel stores data to clipboard so don;t know how to bring it into array _Arraydisplay($bArray) MsgBox(0,0,$bArray) return $bArray endfunc func Pastedata() Local $aArray MsgBox(0,0,"wait",1) ;make array based on assumption user has already copied a range to clipboard $aArray = Makearray() ;paste code ;don;t worry about this I got the rest endfunc  
×