Fsharp: List Dir Content

By Xah Lee. Date: .

fsharp: list dir content

// 2025-12-29
// list dir content

open System.IO

let xpath = @"c:/Users/xah/web/xahlee_info/talk_show/"
// or "." for current directory

let files = Directory.GetFiles(xpath)  // Returns string[] of full paths

// s------------------------------

// Or lazily (better for large directories):
let filesSeq = Directory.EnumerateFiles(xpath)  // Returns seq<string>

// Print them
filesSeq |> Seq.iter (printfn "%s")

// s------------------------------

// With a pattern, e.g., only .txt files:
Directory.EnumerateFiles(xpath, "*.txt") |> Seq.iter (printfn "%s")

fsharp: list dir content and all subdirs

open System.IO

let xpath = "c:/Users/xah/web/xahlee_info/talk_show/"

// All files recursively
Directory.EnumerateFiles(xpath, "*.*", SearchOption.AllDirectories)
|> Seq.iter (printfn "%s")

// Or with DirectoryInfo
// dirInfo.EnumerateFiles("*.*", SearchOption.AllDirectories)
// |> Seq.iter (fun fi -> printfn "%s" fi.FullName)