Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get List of Files in Sub Directories for FAKE

Tags:

f#

f#-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?

like image 345
Jon Avatar asked Sep 11 '14 17:09

Jon


2 Answers

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

like image 69
Gus Avatar answered Oct 11 '22 10:10

Gus


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
like image 26
John Reynolds Avatar answered Oct 11 '22 11:10

John Reynolds