Sign in to follow this  
Followers 0
RichE

find files in dir not working

9 posts in this topic

#1 ·  Posted (edited)

I'm writing an app to store info for elite dangerous on systems I visit and what to trade their and it's facilities, the data will sit in this structure:

Data -

         System1 -

                       Station1.ini

                       Station2.ini

         System2 -

                       Station1.ini

                       Station2.ini

 
etc etc
 
my problem is, on initial run the data folder is created (as it should), then I populate data with said systems (which it does), and create stations (which it does), but on the search tab, when I click on a system from the list, it won't read the files in that folder for some reason, I've tested it reading from the top level and it populates.
 
anyone got any ideas why it won't read the ini files into the combo control on the search page..?
 
Code
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.12.0
 Author:         myName

 Script Function:
    Elite Dangerous - Navigators Yoeman.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <TreeViewConstants.au3>

;declare variables
$data = @ScriptDir & "\data"

;check for data dir existance, if not create it
if fileexists($data) Then
Else
    dircreate($data)
EndIf


#Region ### START Koda GUI section ### Form=
$NYMain = GUICreate("Navigators Yeoman", 919, 559, 203, 107)
$Tab1 = GUICtrlCreateTab(8, 8, 905, 505)

$TabSearch = GUICtrlCreateTabItem("Search")
GUICtrlSetState(-1,$GUI_SHOW)
$sys_list = GUICtrlCreateList("", 16, 50 , 200, 450)

$station_list = GUICtrlCreateCombo("", 220, 50, 450, 25)


$TabStation = GUICtrlCreateTabItem("Add Station")

    $Stn_submit = GUICtrlCreateButton("Submit", 809, 476, 97, 33)
    GUICtrlSetColor(-1, 0x0000C0)

    $Sys_Select = GUICtrlCreateCombo("Select System", 16, 56, 889, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))


    $Stn_Name = GUICtrlCreateInput("Station Name", 16, 88, 449, 21)

$Facilities = GUICtrlCreateGroup(" Facilities ", 16, 120, 457, 385)

    $cx_Repairs = GUICtrlCreateCheckbox("Repairs", 24, 138, 97, 17)
    $cx_Contacts = GUICtrlCreateCheckbox("Contacts", 24, 168, 97, 17)
    $cx_Munitions = GUICtrlCreateCheckbox("Munitions", 24, 188, 97, 17)
    $cx_BMarket = GUICtrlCreateCheckbox("Black Market", 24, 208, 97, 17)
    $cx_Outfitters = GUICtrlCreateCheckbox("Outfitters", 24, 228, 97, 17)
    $cx_Shipyard = GUICtrlCreateCheckbox("ShipYard", 24, 248, 97, 17)
    $cx_cartographer = GUICtrlCreateCheckbox("Cartographer", 24, 268, 97, 17)
    $cx_largepad = GUICtrlCreateCheckbox("Large Pad", 24, 288, 97, 17)
    $cx_mediumpad = GUICtrlCreateCheckbox("Medium Pad", 24, 310, 97, 17)
    $cx_Smallpad = GUICtrlCreateCheckbox("Small Pad", 24, 330, 97, 17)

    GUICtrlCreateGroup("", -99, -99, 1, 1)

$Comments = GUICtrlCreateEdit("", 480, 88, 425, 385)

GUICtrlCreateTabItem("")
    $Add_sys = GUICtrlCreateButton("Add System", 8, 520, 129, 33)

    Local $hSearch = FileFindFirstFile($data & "\*")

    ; Check if the search was successful, if not display a message and return False.
    If $hSearch = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.")

    EndIf

    ; Assign a Local variable the empty string which will contain the files names found.
    Local $sFileName = "", $iResult = 0

    GUICtrlSetColor(-1, 0x0000C0)

    While 1
        $sFileName = FileFindNextFile($hSearch)
        ; If there is no more file matching the search.
        If @error Then ExitLoop

        ; Display the file name.

        $iResult = guictrlsetdata($sys_list, $sFileName & @CR)
        $iResult = guictrlsetdata($Sys_Select, $sFileName)

    WEnd


    ; Close the search handle.
    FileClose($hSearch)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Add_sys
            $SN = InputBox("Add new system", "System Name")
            if $SN = "" or fileexists($data & "\" & $sn) then
                Msgbox(48,"Navigators Yeoman", "System already exists or there was an error!", 5)
            Else
                dircreate($data & "\" & $sn)
                msgbox(64,"Navigators Yeoman", "System Created", 5)
                guictrlsetdata($sys_list, $sn, $sys_list)
                guictrlsetdata($Sys_Select, $sn, $Sys_Select)
            EndIf
        Case $Stn_submit
            $sysname = guictrlread($Sys_Select)
            $stnname = guictrlread($Stn_Name)
            $Stn_coms = Guictrlread($comments)
            $f_Repairs = Guictrlread($cx_Repairs)
            $f_Contacts = Guictrlread($cx_Contacts)
            $f_Munitions = Guictrlread($cx_Munitions)
            $f_BMarket = Guictrlread($cx_BMarket)
            $f_Outfitters = Guictrlread($cx_Outfitters)
            $f_Shipyard = Guictrlread($cx_Shipyard)
            $f_Cartographer = Guictrlread($cx_cartographer)
            $f_Lpad = Guictrlread($cx_largepad)
            $f_Mpad = Guictrlread($cx_mediumpad)
            $f_Spad = Guictrlread($cx_Smallpad)
            IniWrite($data & "\" & $sysname & "\" & $stnname &".ini", "Station-Details", "Name", $stnname)
            IniWrite($data & "\" & $sysname & "\" & $stnname &".ini", "Facilities", "Repairs", $f_Repairs)
            IniWrite($data & "\" & $sysname & "\" & $stnname &".ini", "Facilities", "Contacts", $f_Contacts)
            IniWrite($data & "\" & $sysname & "\" & $stnname &".ini", "Facilities", "Munitions", $f_Munitions)
            IniWrite($data & "\" & $sysname & "\" & $stnname &".ini", "Facilities", "Bmarket", $f_BMarket)
            IniWrite($data & "\" & $sysname & "\" & $stnname &".ini", "Facilities", "Outfitters", $f_Outfitters)
            IniWrite($data & "\" & $sysname & "\" & $stnname &".ini", "Facilities", "Shipyard", $f_Shipyard)
            IniWrite($data & "\" & $sysname & "\" & $stnname &".ini", "Facilities", "Cartographers", $f_Cartographer)
            IniWrite($data & "\" & $sysname & "\" & $stnname &".ini", "Facilities", "Lpad", $f_Lpad)
            IniWrite($data & "\" & $sysname & "\" & $stnname &".ini", "Facilities", "Mpad", $f_Mpad)
            IniWrite($data & "\" & $sysname & "\" & $stnname &".ini", "Facilities", "spad", $f_Spad)
            IniWrite($data & "\" & $sysname & "\" & $stnname &".ini", "Comments", "Comments", $Stn_coms)
        Case $sys_list
            $Sys_sel = Guictrlread($sys_list)
            msgbox(64,"", $Sys_sel)
            $nSearch = FileFindFirstFile(@ScriptDir & "\data\" & $sys_sel & "\*.ini")
            ; Check if the search was successful, if not display a message.
            If $nSearch = -1 Then
                MsgBox($MB_SYSTEMMODAL, "Navigators Yeoman", "Error: No Stations Found")
            EndIf

            ; Assign a Local variable the empty string which will contain the files names found.
            Local $nName = "", $nResult = 0

            While 1
                $nName = FileFindNextFile($nSearch)
                ; If there is no more file matching the search.
                If @error Then ExitLoop

                ; Display the file name.
                $nResult = GUICtrlsetdata($station_list, StringLeft($nName, stringlen($nName)-4))
            WEnd

            ; Close the search handle.
            FileClose($nSearch)

    EndSwitch
WEnd
 
regards
 
Rich
Edited by RichE

RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites



RichE,

2 questions:

- 1. Why write your own FindFirst/NextFile structure when AutoIt has several functions (FileListToArray/_FileListToArray/_FileListToArrayRec to get file lists for you without all the fuss? :huh:

- 2. Does this script interact with the game itself or merely read from a file structure on disc. If you read the Forum rules (there is also a link at bottom right of each page) you will understand why I ask. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

No it doesn't interact with the program it's for me to use as a sort of memo pad to keep info of where I've been.

It not a game bot and i understand the forum rules, and hopefully this does not infringe them


RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites

RichE

it doesn't interact with the program

Delighted to hear it. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

but I'm still a bit confused as to why the inbuilt function works further up the script, but then doesn't work further down the script

what I've found is if I put the select folder directly into the script it works, but if I guictrlread it in it does not, yet it msgbox's correctly out ???

$sname = Guictrlread($sys_list)
msgbox(64, "" , $sname)
$hSearch = FileFindFirstFile($data & "" & $sname & "*.ini")

RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites

RichE,

Use StringToBinary on the $sName string and see if there are any additional invisible characters appended to the name - that would invalidate the final path. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I use this to test...

msgbox(64, "" , $data & "" & $sname & "*.ini")

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks guys, there was whitespace at the end, it's working now :D


RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites

RichE,

An old tip, but a good one. Glad it worked. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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