Jump to content

_FileWriteFromArray from 2D Array [BUG]


Recommended Posts

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
Link to comment
Share on other sites

  • Replies 46
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I already posted a trac ticket #2125

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

water has already posted a bug in Trac #2125.

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
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

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...