Sign in to follow this  
Followers 0
johnmcloud

_FileWriteFromArray from 2D Array [BUG]

47 posts in this topic

#1 ·  Posted (edited)

Hi guys, i have made this script:

$File = _RecFileListToArray("C:\Test", "*.*", 1, 0, 0, 2, "", "")
If IsArray($File) Then
    For $i = 1 To $File[0]
        $Time = FileGetTime($File[$i])
        $dmyyyy = $Time[2] & "/" & $Time[1] & "/" & $Time[0]
        MsgBox(0,"FileDate", $File[$i] & " - " & $dmyyyy)
    Next
EndIf

The script working with MsgBox, so i have try to write the result on a txt like this:

$ToWrite = $File[$i] & " - " & $dmyyyy
$Log = @TempDir & "\log.txt"
$LogCreate = FileOpen(@TempDir & "\log.txt", 1)
_FileWriteFromArray($LogCreate, $ToWrite)
FileClose($LogCreate)

But not working, i have only the filename but not the date. What is the problem?

Thanks for support :)

Edited by johnmcloud

Share this post


Link to post
Share on other sites



What you want to do is to add a column (holding the date of the file) to the existing array $file and then write this array do disk.

Add the column to the array using this code:

Redim $File[UBound($File)][UBound($File, 2)+1]
Then fill the last element of each row with the date and write the file to disk.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks water, but i don't understand :)

If you can, make an example, i've never used Ubound and Redim

Edited by johnmcloud

Share this post


Link to post
Share on other sites

You want this?

#include<_RecFileListToArray.au3>
#include<Array.au3>
;~ Func _RecFileListToArray($sInitialPath, $sInclude_List = "*", $iReturn = 0, $iRecur = 0, $iSort = 0, $iReturnPath = 1, $sExclude_List = "")
$File = _RecFileListToArray(@ScriptDir, "*.*", 1, 0, 0, 2, "")
;~ _ArrayDisplay($File)
Global $newArray[UBound($File)][2]
For $i = 1 To UBound($File) - 1
$Time = FileGetTime($File[$i])
$dmyyyy = $Time[2] & "/" & $Time[1] & "/" & $Time[0]
$newArray[$i][0] = $File[$i]
$newArray[$i][1] = $dmyyyy
Next
_ArrayDisplay($newArray)

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I just did a quick check and noticed that function _RecFileListToArray onyl returns a 1D array. My first approach doesn't work because ReDim can't change a 1D array to a 2D array.

But this should work

#include <recfilelisttoarray.au3>
#include <array.au3>
$File = _RecFileListToArray("C:Temp", "*.*", 1, 0, 0, 2, "", "")
ConsoleWrite(@error & @CRLF)
_Arraydisplay($File)
If IsArray($File) Then
    Global $OutFile[UBound($File)][2] = [[$File[0],2]]
    For $i = 1 To $File[0]
        $Time = FileGetTime($File[$i])
        $OutFile[$i][0] = $File[$i]
        $OutFile[$i][1] = $Time[2] & "/" & $Time[1] & "/" & $Time[0]
    Next
EndIf
_Arraydisplay($OutFile)
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks guys, but both give me error:

Xenobiologist:

On main script:

.File.au3 (256) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If FileWrite($hFile, $a_Array[$x] & @CRLF) = 0 Then
If FileWrite($hFile, ^ ERROR
>Exit code: 1   Time: 4.914

On a empty script with only the code:

.Test1.au3 (7) : ==> Array variable subscript badly formatted.:
Global $newArray[UBound($File)][2]
Global $newArray[^ ERROR
>Exit code: 1   Time: 0.304

water:

On main script

.Test.au3 (298) : ==> Expected a "=" operator in assignment statement.:
$Outfile[$i][0] = $Outfile[$i]
$Outfile^ ERROR
>Exit code: 1   Time: 2.814

On a empty script with only the code:

.Test1.au3 (15) : ==> Variable used without being declared.:
_Arraydisplay($OutFile)
_Arraydisplay(^ ERROR
>Exit code: 1   Time: 0.318
Edited by johnmcloud

Share this post


Link to post
Share on other sites

Line 298 is not within the code I provided. Seems to be caused by an #include of your code.

Can you post the code that returns the error?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Here we are:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <RecFileListToArray.au3> ; External UDF
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GUIConstants.au3>
#include <Constants.au3>
#Include <GuiEdit.au3>
#include <WinAPI.au3>
#include <Array.au3>
#include <Date.au3>
#include <File.au3>
Edited by johnmcloud

Share this post


Link to post
Share on other sites

You can run my test script without any additional code. Just change "C:Temp" to "C:Test".

My script errors if the array returned by _RecFileListToArray does not exist.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Sorry man, i have take temp for test

The problem is if i enable this string:

_FileWriteFromArray($LogCreate, $OutFile, 1)

I have this error:

.File.au3 (256) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If FileWrite($hFile, $a_Array[$x] & @CRLF) = 0 Then
If FileWrite($hFile, ^ ERROR
>Exit code: 1   Time: 5.482

With only _Arraydisplay($OutFile) work, with _FileWriteFromArray i have the error

Thanks for your time

Edited by johnmcloud

Share this post


Link to post
Share on other sites

There seems to be a bug in _FileWriteFromArray for 2D arrays.

What version of Autoit do you use?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I have 3.3.6.0.

Now I have try to install the 3.3.8.0 + Scite Full

.file.au3 (272) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$s_Temp &= $s_Delim & $a_Array[$x][$y]
$s_Temp &= $s_Delim & ^ ERROR
->15:30:48 AutoIT3.exe ended.rc:1
>Exit code: 1   Time: 1.986

Different error, same result. A question: It possible to divide the array in 1D and write them separately on the log? Or Make this 2D in 1D?

Edited by johnmcloud

Share this post


Link to post
Share on other sites

Replace line 271 ("For $y = 1 To $iDims") in the include File.au3 with "For $y = 0 To $iDims-1"


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

This is the result:

12|12|2
C:TestAutoIt3Au3Check.dat|C:TestAutoIt3Au3Check.dat|23/12/2011
C:TestAutoIt3Au3Check.exe|C:TestAutoIt3Au3Check.exe|23/12/2011
C:TestAutoIt3Au3Info.exe|C:TestAutoIt3Au3Info.exe|23/12/2011
C:TestAutoIt3Au3Info_x64.exe|C:TestAutoIt3Au3Info_x64.exe|23/12/2011
C:TestAutoIt3AutoIt v3 Website.url|C:TestAutoIt3AutoIt v3 Website.url|21/12/2011
C:TestAutoIt3AutoIt.chm|C:TestAutoIt3AutoIt.chm|23/12/2011
C:TestAutoIt3AutoIt3.chm|C:TestAutoIt3AutoIt3.chm|23/12/2011
C:TestAutoIt3AutoIt3.exe|C:TestAutoIt3AutoIt3.exe|23/12/2011
C:TestAutoIt3AutoIt3Help.exe|C:TestAutoIt3AutoIt3Help.exe|21/12/2011
C:TestAutoIt3AutoIt3_x64.exe|C:TestAutoIt3AutoIt3_x64.exe|23/12/2011
C:TestAutoIt3UDFs3.chm|C:TestAutoIt3UDFs3.chm|23/12/2011
C:TestAutoIt3Uninstall.exe|C:TestAutoIt3Uninstall.exe|06/02/2012

So it's a bug. I can replace the | with a space, but how to remove the duplicate path?

Edited by johnmcloud

Share this post


Link to post
Share on other sites

My bad. The correct line should read: "For $y = 1 To $iDims-1"


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

My bad. The correct line should read: "For $y = 1 To $iDims-1"

Ok, nice, thanks. You will post a bug for this or i'll do by myself? It's not a problem for me but i think you are a MVP so maybe it's better solution. Tell me what to do :)

Share this post


Link to post
Share on other sites

I already posted a trac ticket #2125


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

water has already posted a bug in Trac #2125.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

I have see and confirmed it.

Thanks

Share this post


Link to post
Share on other sites

My last problem. I have integrate the script in the main script, but i have error if the array is empty:

Final.au3 (300) : ==> Subscript used with non-Array variable.:
$OutFile[$i][1] = $Time[2] & "/" & $Time[1] & "/" & $Time[0]
$OutFile[$i][1] = $Time^ ERROR
->17:11:45 AutoIT3.exe ended.rc:1
>Exit code: 1    Time: 10.577

How to avoid this? Thanks for support to all

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  
Followers 0

  • Similar Content

    • blantek212
      By blantek212
      Hello everyone.
      I need help with scripts. I have some code which creates array, and next writes this array to a file (function _FileWriteFromArray).
      In the next step it creates second array. I would like to add this array to previous file, but function _FileWriteFromArray repleaces only content in the file.
      Is there any other way to solve this problem?
    • TheDcoder
      By TheDcoder
      Hi, I have a 2D array with 2 columns, the 1st column contains a "version string" and the 2nd column contains a generic string. I want to sort it in the descending order so the latest version comes first.
      #include <Array.au3> Local $aVersionsAndReleases[4][2] = [["0.2.8.9", "Release #1"], ["0.2.9.10", "Release #3"], ["0.2.9.11", "Release #4"], ["0.2.8.10", "Release #2"]] _ArraySort($aVersionsAndReleases, 1) ConsoleWrite(_ArrayToString($aVersionsAndReleases, ' - ')) _ArrayDisplay($aVersionsAndReleases) Unfortunately, _ArraySort isn't working here . This is the output generated by the script:
      0.2.9.11 - Release #4 0.2.9.10 - Release #3 0.2.8.9 - Release #1 0.2.8.10 - Release #2 The expected result should be:
      0.2.9.11 - Release #4 0.2.9.10 - Release #3 0.2.8.10 - Release #2 0.2.8.9 - Release #1 I am looking to develop an function which does this... but I don't know where to start . Can someone help me get started? Thanks in Advance!
      - TD.
    • StillLearningThisStuff
      By StillLearningThisStuff
      Hello all,
      Summary: I have a basic piece of code that is to be a part of a much larger project; I just can't seem to get the right output. I'm retrieving two lots of powershell data into 2 x 1d arrays and trying to add them into a single 2d array. Retrieving the data together into the 2d array seemed harder, due to the application names varying too much to string split. Data being pulled is application name and GUID. From here I will use this info in a drop down box and an uninstall button to run the required command to remove the selected software (have this sorted already).
      Problem: When I merge the data it doesn't put the application name and GUID on the same row in differing columns eg. my test box has 24 applications plus some superfluous data from Powershell to be cleaned up by the _arraydeletes. Instead I end up with an array with 58 rows and 2 columns; whereas my temp 1d arrays have 28 rows. As you can see I've tried both _ArrayInsert and _ArrayAdd but I still get the same result.
      Question: Is there something that I'm doing wrong in putting the data into the 2d array or do I just need to do some more post processing to tidy it up and align the names and GUIDs?
      Code:
      #include <Array.au3> $Cmd1 = (" /c Powershell.exe " & Chr(34) & "Get-WmiObject -Class win32reg_addremoveprograms | where {$_.ProdID -like " & Chr(34) & Chr(123) & Chr(42) & Chr(125) & Chr(34) & "} | select DisplayName" & Chr(34)) $Cmd2 = (" /c Powershell.exe " & Chr(34) & "Get-WmiObject -Class win32reg_addremoveprograms | where {$_.ProdID -like " & Chr(34) & Chr(123) & Chr(42) & Chr(125) & Chr(34) & "} | select ProdID" & Chr(34)) Global $aNameGUID[1][2] ;_ArrayDisplay($aNameGUID) ReadApps($Cmd1,0) ;_ArrayDisplay($aNameGUID) ReadApps($Cmd2,1) _ArrayDisplay($aNameGUID) Terminate() Func ReadApps($Command,$col) $DOS = Run(@ComSpec & $Command, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($DOS) $DOSOut = StdoutRead($DOS) ;MsgBox(0,"Data",$DOSOut) ;Show the line items that we want in the array Local $tmpArray = StringSplit(StringTrimRight(StringStripCR($DOSOut), StringLen(@CRLF)), @CRLF) If @error Then MsgBox(0,"FAIL","I failed to find objects") Exit Else _ArrayDisplay($tmpArray) EndIf ;_ArrayDelete($tmpArray, 3) ;_ArrayDelete($tmpArray, 2) ;_ArrayDelete($tmpArray, 1) ;$tmpArray[0] = $tmpArray[0] - 3 For $i = 0 To UBound($tmpArray) - 1 ;_ArrayAdd($aNameGUID, $tmpArray[$i], $col) _ArrayInsert($aNameGUID, 0, $tmpArray[$i], $col) Next $tmpArray = 0 EndFunc ;==>ReadApps While 1 Sleep(1500) WEnd Func Terminate() Exit 0 EndFunc ;==>Terminate Thanks in advance,
      Luxyboy
    • UEZ
      By UEZ
      Some Graphical Examples using GDI+ Vol. II build 2016-05-07 (33 examples)
       
      This is the continuation of "Some Graphical Examples using GDI+ Vol. I" with currently 33 examples in "snippet style".
       
      For downloads and screenshots just visit the download section.
       
      All examples should properly run on Win7+ operating systems / tested on AutoIt v3.3.14.2!
       
      More examples will follow from time to time.
       
      Thanks to Eukalyptus!
       
      Please report any issues / feel free to post any comment.
       
      Have fun.
    • UEZ
      By UEZ
      Some Graphical Examples using GDI+ Vol. II (33 examples)
       
      This is the continuation of "Some Graphical Examples using GDI+ Vol. I".
       
      Have fun.