Search code examples
f#listboxdirectoryfile-listing

Listing directory files in a listbox and open them


I have to list all the files located in my project directory (so using a relative path) in a listbox. I also need to open the selected file in the list (click or double click, it's the same). This is my code:

let list = new ListBox(Height=600, Dock=DockStyle.Right)
let dir = new DirectoryInfo(@"c:\tiles\")
list.Items.Add(dir.GetFiles())

when I launch my project I have a "System.IO.FileInfo[]" string in the ListBox. How to fix it? What is the correct path string for the project directory?

And about the opening problem?

P.S: I have to load just *.png file in Bitmaps.


Solution

  • done in this way:

    let dir = new DirectoryInfo(path)
    for file in dir.GetFiles() do
      list.Items.Add(file) |> ignore