Jump to content

ListFileToArray Problems


 Share

Recommended Posts

Haiii guys, I am trying to make a bingo game to start a projcet :DD...

However I wanted to make it rather Customable so that you could make your own patterns and such.

I used the ListFilesToArray UDF by SmOke_N.

Did a test to see if I get anything out of it. Before program start.

Nothing happens...It's just down in the process bar doing nothing

The UDF:

;===============================================================================

;

; Description: lists all or preferred files and or folders in a specified path (Similar to using Dir with the /B Switch)

; Syntax: _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '')

; Parameter(s): $sPath = Path to generate filelist for

; $sFilter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details, support now for multiple searches

; Example *.exe; *.txt will find all .exe and .txt files

; $iFlag = determines weather to return file or folders or both.

; $sExclude = exclude a file from the list by all or part of its name

; Example: Unins* will remove all files/folders that start with Unins

; $iFlag=0(Default) Return both files and folders

; $iFlag=1 Return files Only

; $iFlag=2 Return Folders Only

;

; Requirement(s): None

; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path

; On Failure - Returns the an empty string "" if no files are found and sets @Error on errors

; @Error or @extended = 1 Path not found or invalid

; @Error or @extended = 2 Invalid $sFilter or Invalid $sExclude

; @Error or @extended = 3 Invalid $iFlag

; @Error or @extended = 4 No File(s) Found

;

; Author(s): SmOke_N

; Note(s): The array returned is one-dimensional and is made up as follows:

; $array[0] = Number of FilesFolders returned

; $array[1] = 1st FileFolder

; $array[2] = 2nd FileFolder

; $array[3] = 3rd FileFolder

; $array[n] = nth FileFolder

;

; All files are written to a "reserved" .tmp file (Thanks to gafrost) for the example

; The Reserved file is then read into an array, then deleted

;===============================================================================

Func _FileListToArrayEx($s_path, $s_mask = "*.*", $i_flag = 0, $s_exclude = -1, $f_recurse = True, $f_full_path = True)

If FileExists($s_path) = 0 Then Return SetError(1, 1, 0)

; Strip trailing backslash, and add one after to make sure there's only one

$s_path = StringRegExpReplace($s_path, "[/]+z", "") & ""

; Set all defaults

If $s_mask = -1 Or $s_mask = Default Then $s_mask = "*.*"

If $i_flag = -1 Or $i_flag = Default Then $i_flag = 0

If $s_exclude = -1 Or $s_exclude = Default Then $s_exclude = ""

; Look for bad chars

If StringRegExp($s_mask, "[/:><|]") Or StringRegExp($s_exclude, "[/:><|]") Then

Return SetError(2, 2, 0)

EndIf

; Strip leading spaces between semi colon delimiter

$s_mask = StringRegExpReplace($s_mask, "s*;s*", ";")

If $s_exclude Then $s_exclude = StringRegExpReplace($s_exclude, "s*;s*", ";")

; Confirm mask has something in it

If StringStripWS($s_mask, 8) = "" Then Return SetError(2, 2, 0)

If $i_flag < 0 Or $i_flag > 2 Then Return SetError(3, 3, 0)

; Validate and create path + mask params

Local $a_split = StringSplit($s_mask, ";"), $s_hold_split = ""

For $i = 1 To $a_split[0]

If StringStripWS($a_split[$i], 8) = "" Then ContinueLoop

If StringRegExp($a_split[$i], "^..*?..*?z") Then

$a_split[$i] &= "*" & $a_split[$i]

EndIf

$s_hold_split &= '"' & $s_path & $a_split[$i] & '" '

Next

$s_hold_split = StringTrimRight($s_hold_split, 1)

If $s_hold_split = "" Then $s_hold_split = '"' & $s_path & '*.*"'

Local $i_pid, $s_stdout, $s_hold_out, $s_dir_file_only = "", $s_recurse = "/s "

If $i_flag = 1 Then $s_dir_file_only = ":-d"

If $i_flag = 2 Then $s_dir_file_only = " :D"

If Not $f_recurse Then $s_recurse = ""

$i_pid = Run(@ComSpec & " /c dir /b " & $s_recurse & "/a" & $s_dir_file_only & " " & $s_hold_split, "", @SW_HIDE, 4 + 2)

While 1

$s_stdout = StdoutRead($i_pid)

If @error Then ExitLoop

$s_hold_out &= $s_stdout

WEnd

$s_hold_out = StringRegExpReplace($s_hold_out, "v+z", "")

If Not $s_hold_out Then Return SetError(4, 4, 0)

; Parse data and find matches based on flags

Local $a_fsplit = StringSplit(StringStripCR($s_hold_out), @LF), $s_hold_ret

$s_hold_out = ""

If $s_exclude Then $s_exclude = StringReplace(StringReplace($s_exclude, "*", ".*?"), ";", "|")

For $i = 1 To $a_fsplit[0]

If $s_exclude And StringRegExp(StringRegExpReplace( _

$a_fsplit[$i], "(.*?[/]+)*(.*?z)", "2"), "(?i)Q" & $s_exclude & "E") Then ContinueLoop

If StringRegExp($a_fsplit[$i], "^w:[/]+") = 0 Then $a_fsplit[$i] = $s_path & $a_fsplit[$i]

If $f_full_path Then

$s_hold_ret &= $a_fsplit[$i] & Chr(1)

Else

$s_hold_ret &= StringRegExpReplace($a_fsplit[$i], "((?:.*?[/]+)*)(.*?z)", "$2") & Chr(1)

EndIf

Next

$s_hold_ret = StringTrimRight($s_hold_ret, 1)

If $s_hold_ret = "" Then Return SetError(5, 5, 0)

Return StringSplit($s_hold_ret, Chr(1))

EndFunc

My Code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <UDF/FileToArryUDF.au3>
#include <array.au3>

$GameArray = _FileListToArrayEx("",'*.ini',1)
MsgBox(0,"",$GameArray[0])
MainMenu()

;GUICtrlSetData($Games,$GamesArray[])
;Starting the GUI
Func MainMenu()
#Region GUI
$Main = GUICreate("Bingo Start up", 306, 542, 192, 124)
$Start = GUICtrlCreateButton("Start", 144, 424, 145, 33)
$Edit = GUICtrlCreateButton("Edit Game", 144, 488, 145, 33)
$Games = GUICtrlCreateList("", 8, 8, 121, 513)
GUISetState(@SW_SHOW)
#EndRegion

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Start
Start()
Exit
Case $Edit
Edit()
Exit
EndSwitch
WEnd

EndFunc

;Not yet made :DD
Func Start()

EndFunc

Func Edit()

;So we start off with a name of projcet
$Name = InputBox("Name of Game", "Please Choose a name for your game or edit an existing game")
;If it exists...Then open else make a new <-- there where I have problems D:
$Exists = FileExists($Name & ".ini")
If $Exists = 0 Then
FileOpen($Name & ".ini",1)
IniWriteSection($Name & ".ini","Form",@LF)
;Make a new window :D...
#Region GUI
;Gui blah blah blah blah
#include
#include
#include
#include

$Edit = GUICreate("Edit", 209, 163, 204, 132)
$Rows = GUICtrlCreateInput("", 64, 16, 121, 21)
$Collons = GUICtrlCreateInput("", 64, 48, 121, 21)
$MinNumber = GUICtrlCreateInput("", 88, 88, 25, 21)
$MaxNumber = GUICtrlCreateInput("", 128, 88, 25, 21)
$Done = GUICtrlCreateButton("Done", 19, 120, 73, 25)
$Next = GUICtrlCreateButton("Next", 112, 120, 73, 25)

$RowLabel = GUICtrlCreateLabel("Rows", 16, 16, 31, 17)
$CollonsLabel = GUICtrlCreateLabel("Collons", 16, 48, 38, 17)
$NumberLabel = GUICtrlCreateLabel("Number from", 16, 88, 64, 17)
$NoEdit = GUICtrlCreateLabel("-", 120, 88, 7, 17)

;Reads the texts of my Input boxes (Errors here)
GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Done
$ReadRows = GUICtrlRead($Rows)
$ReadCollons = GUICtrlRead($Collons)
$ReadMinN = GUICtrlRead($MinNumber)
$ReadMaxN = GUICtrlRead($MaxNumber)

IniWrite($Name & ".ini", "Form", "Rows", $ReadRows)
IniWrite($Name & ".ini", "Form", "Collons", $ReadCollons)
IniWrite($Name & ".ini", "Form", "MinN", $ReadMinN)
IniWrite($Name & ".ini", "Form", "MaxN", $ReadMaxN)
Exit
Case $Next
Exit
EndSwitch



WEnd

#EndRegion
Else
MsgBox(0,"LOL","shit exists")
EndIF
EndFunc
Edited by Zanaj
Link to comment
Share on other sites

You might start to debug your problem by first giving the function "_FileListToArrayEx" a path from which to list files.

And after that, try checking for @error after function calls.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

You have not specified the path to search for .ini file in the func _FileListToArrayEx

Try this:

#include <array.au3>
$sSearchPath = @ScriptDir & "\Test";The path where the .ini are stored

$GameArray = _FileListToArrayEx($sSearchPath, '*.ini', 1)
If @error Then
    MsgBox(16, "Error", "Unable to find any .ini files")
    Exit
EndIf

_ArrayDisplay($GameArray) ;Debug Only

Func _FileListToArrayEx($s_path, $s_mask = "*.*", $i_flag = 0, $s_exclude = -1, $f_recurse = True, $f_full_path = True)

    If FileExists($s_path) = 0 Then Return SetError(1, 1, 0)

    ; Strip trailing backslash, and add one after to make sure there's only one
    $s_path = StringRegExpReplace($s_path, "[\\/]+\z", "") & "\"

    ; Set all defaults
    If $s_mask = -1 Or $s_mask = Default Then $s_mask = "*.*"
    If $i_flag = -1 Or $i_flag = Default Then $i_flag = 0
    If $s_exclude = -1 Or $s_exclude = Default Then $s_exclude = ""

    ; Look for bad chars
    If StringRegExp($s_mask, "[/:><\|]") Or StringRegExp($s_exclude, "[/:><\|]") Then
        Return SetError(2, 2, 0)
    EndIf

    ; Strip leading spaces between semi colon delimiter
    $s_mask = StringRegExpReplace($s_mask, "\s*;\s*", ";")
    If $s_exclude Then $s_exclude = StringRegExpReplace($s_exclude, "\s*;\s*", ";")

    ; Confirm mask has something in it
    If StringStripWS($s_mask, 8) = "" Then Return SetError(2, 2, 0)
    If $i_flag < 0 Or $i_flag > 2 Then Return SetError(3, 3, 0)

    ; Validate and create path + mask params
    Local $a_split = StringSplit($s_mask, ";"), $s_hold_split = ""
    For $i = 1 To $a_split[0]
        If StringStripWS($a_split[$i], 8) = "" Then ContinueLoop
        If StringRegExp($a_split[$i], "^\..*?\..*?\z") Then
            $a_split[$i] &= "*" & $a_split[$i]
        EndIf
        $s_hold_split &= '"' & $s_path & $a_split[$i] & '" '
    Next
    $s_hold_split = StringTrimRight($s_hold_split, 1)
    If $s_hold_split = "" Then $s_hold_split = '"' & $s_path & '*.*"'

    Local $i_pid, $s_stdout, $s_hold_out, $s_dir_file_only = "", $s_recurse = "/s "
    If $i_flag = 1 Then $s_dir_file_only = ":-d"
    If $i_flag = 2 Then $s_dir_file_only = " "
    If Not $f_recurse Then $s_recurse = ""

    $i_pid = Run(@ComSpec & " /c dir /b " & $s_recurse & "/a" & $s_dir_file_only & " " & $s_hold_split, "", @SW_HIDE, 4 + 2)

    While 1
        $s_stdout = StdoutRead($i_pid)
        If @error Then ExitLoop
        $s_hold_out &= $s_stdout
    WEnd

    $s_hold_out = StringRegExpReplace($s_hold_out, "\v+\z", "")
    If Not $s_hold_out Then Return SetError(4, 4, 0)

    ; Parse data and find matches based on flags
    Local $a_fsplit = StringSplit(StringStripCR($s_hold_out), @LF), $s_hold_ret
    $s_hold_out = ""

    If $s_exclude Then $s_exclude = StringReplace(StringReplace($s_exclude, "*", ".*?"), ";", "|")

    For $i = 1 To $a_fsplit[0]
        If $s_exclude And StringRegExp(StringRegExpReplace( _
                $a_fsplit[$i], "(.*?[\\/]+)*(.*?\z)", "\2"), "(?i)\Q" & $s_exclude & "\E") Then ContinueLoop
        If StringRegExp($a_fsplit[$i], "^\w:[\\/]+") = 0 Then $a_fsplit[$i] = $s_path & $a_fsplit[$i]
        If $f_full_path Then
            $s_hold_ret &= $a_fsplit[$i] & Chr(1)
        Else
            $s_hold_ret &= StringRegExpReplace($a_fsplit[$i], "((?:.*?[\\/]+)*)(.*?\z)", "$2") & Chr(1)
        EndIf
    Next

    $s_hold_ret = StringTrimRight($s_hold_ret, 1)
    If $s_hold_ret = "" Then Return SetError(5, 5, 0)

    Return StringSplit($s_hold_ret, Chr(1))
EndFunc   ;==>_FileListToArrayEx

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Got it to work I used the Help thingy and found out it was actually already added xD...Damn me for googling first and check help file after!

However I ran into a new problem adding them into a "List" owo...

How should I handle this? Now I got an array I don't need the [0] element nor do I want the last but everything else...How do I do this?

Keep "updating" the List untill there is no more Elements in the array?

Should I repost about this problem?

Edit: Got it to work. For futher persons who may find this my code turned out like this:

#include 
#include 
#include 
#include 
#include 
#include 


MainMenu()
;Starting the GUI
Func MainMenu()
#Region GUI
$Main = GUICreate("Bingo Start up", 306, 542, 192, 124)
$Start = GUICtrlCreateButton("Start", 144, 424, 145, 33)
$Edit = GUICtrlCreateButton("Edit Game", 144, 488, 145, 33)
$Games = GUICtrlCreateList("", 8, 8, 121, 513)
GUISetState(@SW_SHOW)
#EndRegion
$Path = @ScriptDir & "/Games"
Local $FileList = _FileListToArray($Path,"*.ini",1)
If @error = 1 Then
MsgBox(0, "", "No Folders Found.")
Exit
EndIf
If @error = 4 Then
MsgBox(0, "", "No Files Found.")
Exit
EndIf
For $element In $FileList
$GamesFromArray = StringSplit($element,".ini")
GUICtrlSetData($Games,$GamesFromArray[1])
Next

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Start
Start()
Exit
Case $Edit
Edit()
Exit
EndSwitch
WEnd

EndFunc

;Not yet made :DD
Func Start()

EndFunc

Func Edit()

;So we start off with a name of projcet
$Name = InputBox("Name of Game", "Please Choose a name for your game or edit an existing game")
;If it exists...Then open else make a new <-- there where I have problems D:
$Exists = FileExists($Name & ".ini")
If $Exists = 0 Then
FileOpen($Name & ".ini",1)
IniWriteSection($Name & ".ini","Form",@LF)
;Make a new window :D...
#Region GUI
;Gui blah blah blah blah
#include 
#include 
#include 
#include 

$Edit = GUICreate("Edit", 209, 163, 204, 132)
$Rows = GUICtrlCreateInput("", 64, 16, 121, 21)
$Collons = GUICtrlCreateInput("", 64, 48, 121, 21)
$MinNumber = GUICtrlCreateInput("", 88, 88, 25, 21)
$MaxNumber = GUICtrlCreateInput("", 128, 88, 25, 21)
$Done = GUICtrlCreateButton("Done", 19, 120, 73, 25)
$Next = GUICtrlCreateButton("Next", 112, 120, 73, 25)

$RowLabel = GUICtrlCreateLabel("Rows", 16, 16, 31, 17)
$CollonsLabel = GUICtrlCreateLabel("Collons", 16, 48, 38, 17)
$NumberLabel = GUICtrlCreateLabel("Number from", 16, 88, 64, 17)
$NoEdit = GUICtrlCreateLabel("-", 120, 88, 7, 17)

;Reads the texts of my Input boxes (Errors here)
GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Done
$ReadRows = GUICtrlRead($Rows)
$ReadCollons = GUICtrlRead($Collons)
$ReadMinN = GUICtrlRead($MinNumber)
$ReadMaxN = GUICtrlRead($MaxNumber)

IniWrite($Name & ".ini", "Form", "Rows", $ReadRows)
IniWrite($Name & ".ini", "Form", "Collons", $ReadCollons)
IniWrite($Name & ".ini", "Form", "MinN", $ReadMinN)
IniWrite($Name & ".ini", "Form", "MaxN", $ReadMaxN)
Exit
Case $Next
Exit
EndSwitch



WEnd

#EndRegion
Else
MsgBox(0,"LOL","shit exists")
EndIF
EndFunc
Edited by Zanaj
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...