List all files in a folder in a List Box

This forum is currently in read-only mode.
From the Asset Store
Excel2JSON
$1.20 USD
60% off
Convert multiple Excel files into JSON files and import them into construct3.
  • I'm currently working on a level editor for a game, which is pretty much done. It stores all objects into an array then saves the array out to a file. The loading is also working fine, however the user has to type the name of the level into a box to be able to open it, which is just annoying. So i was wondering if there's a way to get all files in a folder to be listed in a List Box? This way the user can select their level from a list.

    All the level files are stored in AppPath/maps

    Thanks

  • The "File" objects would work well for this. It has an event to loop through each file in a directory, then there's a condition to get the name each file as it loops through. Let me know if you need anymore help.

  • For a very simple list of files, I have used this:

    -> ListBox: Add line File.FileList("F:\Downloads")[/code:2bxjb9by]
    
    Just drop in a listbox and file object, and add that action somewhere. That path is just my download directory, which has hundreds of files. It seems to handle separating each file into a new line just fine.
    
    You can handle selections or double-clicks easily with something like this (which only copies the filename to a text object):
    
    [code:2bxjb9by]+ ListBox: Selection changed
    -> Text: Set text to ListBox.LineText(ListBox.SelectedLine)
    
    or...
    
    + ListBox: Double clicked
    -> Text: Set text to ListBox.LineText(ListBox.SelectedLine)
    [/code:2bxjb9by]
  • Thanks to both of you! Its working perfectly

  • how would you go about displaying only a certain type of file?

    like a particular file extension, is that possible?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • how would you go about displaying only a certain type of file?

    like a particular file extension, is that possible?

    + Your condition...
    -> ListBox: Add line File.FileListFiltered("F:\Downloads", "*.cap")[/code:tghtci61]
    
    This shows me all of the .cap files in my download folder. Check out this wiki page for more that the file object can do:
    
    [url=http://sourceforge.net/apps/mediawiki/construct/index.php?title=File_Object]http://sourceforge.net/apps/mediawiki/c ... ile_Object[/url]
    
    It does have the elements necessary for more complex file and/or directory listing. Also, the Common Dialog Object has some uses in this area, if you don't mind a windows-style requester, though it's not quite as flexible as the file object.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)