Jon
Jon

Reputation: 2784

Get List of Files in Sub Directories for FAKE

I'm trying to use FAKE to build F# files that are located in several sub directories. The filesInDirMatching is from FAKE.

#r @"packages/FAKE/tools/FakeLib.dll"
open System.IO
open Fake
open Fake.FileSystemHelper
open Fake.FscHelper

let allDirs = DirectoryInfo(__SOURCE_DIRECTORY__).GetDirectories "*"
let all = allDirs |> Array.map(fun d -> filesInDirMatching "Example.fs" d)

This all kind of works except that, in the last line, it's creating a 2-dimensional array (since filesInDirMatching creates a new FileDirectory array, I'm guessing). Is it possible to reduce the 2-dimensional array into a one-dimensional array? Or is there a better way of doing this?

Upvotes: 5

Views: 1303

Answers (2)

Gus
Gus

Reputation: 26184

I guess by a 2 dimensional array you mean an array of array (a jagged array).

If so, just replace your Array.map with Array.collect

Upvotes: 4

John Reynolds
John Reynolds

Reputation: 5057

You can flatten the array into a single dimension with Array.concat:

let all = allDirs
          |> Array.map(fun d -> filesInDirMatching "Example.fs" d)
          |> Array.concat

Upvotes: 3

Related Questions