Jump to content

Recommended Posts

Posted (edited)

Hi guys hope you are all well.

Id like to learn how to populate a combo box with filenames (no extensions) from a directory.

The folder can have any type of file, but I only want to grab files with a *.txt extension.

Ideally Id like to be able to sort the combox alphabetically.

I have attached a picture to show you what I am trying to do.

Any help greatly appreciated.

post-65297-0-08834500-1308026737_thumb.j

Edited by Simmy
Posted

_FileListToArray - will get you the list of the files

Make a string "|" delimited from all array elements (without element [0] which is the total count) then use GuiCtrlSetData to populate the combo.

To have it sorted: create the combo with $CBS_SORT option.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Posted

Hi Mass Spammer,

This is what I have so far:

#Include <File.au3>
#Include <Array.au3>

;==============================================
;Get list of files into an array:
;==============================================
$FileList=_FileListToArray("c:\autoittest\me","*.txt",1)
;==============================================
;Error handling:
;==============================================
If @Error=1 Then
    MsgBox (0,"","No Folders Found.")
    Exit
EndIf
If @Error=4 Then
    MsgBox (0,"","No Files Found.")
    Exit
EndIf

_ArrayDisplay($FileList,"$FileList")

;msgbox(0,"Details",$FileList[1])

What I'm not quite sure about is:

a)How to convert the array/delimit the array by a "|"

b)Start at index 2 without the count.

Posted

I'm embarrassed now lol

Sorry enaiman :huh2:

I ran the for next code and placed a msgbox with $string to see what the value of $string is.

It was as follows:

First time through:

Textfile1.txt |

Second time through:

Textile1.txt | Textfile2.txt |

Third time through:

Textfile1.txt | Textfile2.txt | Textfile3.txt |

Does that mean, I need to grab the content of the last time through the loop, and work with that line?

Eg. The

Textfile1.txt | Textfile2.txt | Textfile3.txt

Posted

Does this help?

#Include <File.au3>
#Include <Array.au3>

$FileList=_FileListToArray(@DesktopDir, "*.txt")
If @Error=1 Then
    MsgBox (0,"","No Folders Found.")
    Exit
EndIf
If @Error=4 Then
    MsgBox (0,"","No Files Found.")
    Exit
EndIf

For $i = 0 To $FileList[0]
    $FileList[$i] = StringTrimRight($FileList[$i], 4)
Next


_ArrayDisplay($FileList,"$FileList")
Posted

What about _GUICtrlComboBox_AddDir()? Although it will show .txt at the end of the filename, but its good to know for the future.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Guys, with

_ArrayDisplay($FileList,"$FileList"),

is it possible to only show 1 column and not both?

My attachment shows you what I mean.

post-65297-0-55736100-1308099014_thumb.j

Posted (edited)

Your best bet is to create you own using the ListView Functions. Have a look on the Forum OR at _ArrayDisplay() to get an idea of what to do. Also in my signature there are Examples starting with _GUICtrlListView_ which have an Example of a ListView or two.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

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