Loading .fs files

This script facilitates to load all the .fs files in the specified F# project in correct compilation order.

Copy Source
Copy Link
Tools:

get .fs files in .fsproj file

 1: open System
 2: open System.IO
 3: open System.Text
 4: open System.Text.RegularExpressions
 5: 
 6: let getFsFilesIn projectDirectory =
 7:    
 8:   let fsprojFile = 
 9:     Directory.GetFiles projectDirectory
10:     |> Seq.tryFind(fun file -> (FileInfo file).Extension = ".fsproj")
11: 
12:   if fsprojFile.IsSome then
13:     let content = File.ReadAllText fsprojFile.Value
14:     let matches = Regex.Matches(content,@"<Compile Include=""(\w+\.fs+)\"" />")
15:     seq { for m in matches -> m.Groups.[1].Value }
16:     |> Seq.map(fun filename -> sprintf @"#load ""%s\%s""" projectDirectory filename)
17:     |> String.concat "\n"
18:   else failwith ".fsproj file couldn't find !!!"

Usage

 1: // 1. generate #load directive strings
 2: getFsFilesIn @"(Your F# project directory)"
 3: // 2. get them from the Clipboard
 4: |> System.Windows.Forms.Clipboard.SetText
 5: 
 6: // 3. put them to a script file
 7: // #load "hoge.fs"
 8: // #load "foo.fs"
 9: // #load "bar.fs"
10: // ..
namespace System
namespace System.IO
namespace System.Text
namespace System.Text.RegularExpressions
val getFsFilesIn : string -> string

Full name: Snippet.getFsFilesIn
val projectDirectory : string

  type: string
  implements: IComparable
  implements: ICloneable
  implements: IConvertible
  implements: IComparable<string>
  implements: seq<char>
  implements: Collections.IEnumerable
  implements: IEquatable<string>
val fsprojFile : string option

  type: string option
  implements: Collections.IStructuralEquatable
  implements: IComparable<Option<string>>
  implements: IComparable
  implements: Collections.IStructuralComparable
type Directory =
  class
    static member CreateDirectory : string -> System.IO.DirectoryInfo
    static member CreateDirectory : string * System.Security.AccessControl.DirectorySecurity -> System.IO.DirectoryInfo
    static member Delete : string -> unit
    static member Delete : string * bool -> unit
    static member EnumerateDirectories : string -> System.Collections.Generic.IEnumerable<string>
    static member EnumerateDirectories : string * string -> System.Collections.Generic.IEnumerable<string>
    static member EnumerateDirectories : string * string * System.IO.SearchOption -> System.Collections.Generic.IEnumerable<string>
    static member EnumerateFileSystemEntries : string -> System.Collections.Generic.IEnumerable<string>
    static member EnumerateFileSystemEntries : string * string -> System.Collections.Generic.IEnumerable<string>
    static member EnumerateFileSystemEntries : string * string * System.IO.SearchOption -> System.Collections.Generic.IEnumerable<string>
    static member EnumerateFiles : string -> System.Collections.Generic.IEnumerable<string>
    static member EnumerateFiles : string * string -> System.Collections.Generic.IEnumerable<string>
    static member EnumerateFiles : string * string * System.IO.SearchOption -> System.Collections.Generic.IEnumerable<string>
    static member Exists : string -> bool
    static member GetAccessControl : string -> System.Security.AccessControl.DirectorySecurity
    static member GetAccessControl : string * System.Security.AccessControl.AccessControlSections -> System.Security.AccessControl.DirectorySecurity
    static member GetCreationTime : string -> System.DateTime
    static member GetCreationTimeUtc : string -> System.DateTime
    static member GetCurrentDirectory : unit -> string
    static member GetDirectories : string -> string []
    static member GetDirectories : string * string -> string []
    static member GetDirectories : string * string * System.IO.SearchOption -> string []
    static member GetDirectoryRoot : string -> string
    static member GetFileSystemEntries : string -> string []
    static member GetFileSystemEntries : string * string -> string []
    static member GetFileSystemEntries : string * string * System.IO.SearchOption -> string []
    static member GetFiles : string -> string []
    static member GetFiles : string * string -> string []
    static member GetFiles : string * string * System.IO.SearchOption -> string []
    static member GetLastAccessTime : string -> System.DateTime
    static member GetLastAccessTimeUtc : string -> System.DateTime
    static member GetLastWriteTime : string -> System.DateTime
    static member GetLastWriteTimeUtc : string -> System.DateTime
    static member GetLogicalDrives : unit -> string []
    static member GetParent : string -> System.IO.DirectoryInfo
    static member Move : string * string -> unit
    static member SetAccessControl : string * System.Security.AccessControl.DirectorySecurity -> unit
    static member SetCreationTime : string * System.DateTime -> unit
    static member SetCreationTimeUtc : string * System.DateTime -> unit
    static member SetCurrentDirectory : string -> unit
    static member SetLastAccessTime : string * System.DateTime -> unit
    static member SetLastAccessTimeUtc : string * System.DateTime -> unit
    static member SetLastWriteTime : string * System.DateTime -> unit
    static member SetLastWriteTimeUtc : string * System.DateTime -> unit
  end

Full name: System.IO.Directory
Multiple overloads
Directory.GetFiles(path: string) : string []
Directory.GetFiles(path: string, searchPattern: string) : string []
Directory.GetFiles(path: string, searchPattern: string, searchOption: SearchOption) : string []
module Seq

from Microsoft.FSharp.Collections
val tryFind : ('T -> bool) -> seq<'T> -> 'T option

Full name: Microsoft.FSharp.Collections.Seq.tryFind
val file : string

  type: string
  implements: IComparable
  implements: ICloneable
  implements: IConvertible
  implements: IComparable<string>
  implements: seq<char>
  implements: Collections.IEnumerable
  implements: IEquatable<string>
type FileInfo =
  class
    inherit System.IO.FileSystemInfo
    new : string -> System.IO.FileInfo
    member AppendText : unit -> System.IO.StreamWriter
    member CopyTo : string -> System.IO.FileInfo
    member CopyTo : string * bool -> System.IO.FileInfo
    member Create : unit -> System.IO.FileStream
    member CreateText : unit -> System.IO.StreamWriter
    member Decrypt : unit -> unit
    member Delete : unit -> unit
    member Directory : System.IO.DirectoryInfo
    member DirectoryName : string
    member Encrypt : unit -> unit
    member Exists : bool
    member GetAccessControl : unit -> System.Security.AccessControl.FileSecurity
    member GetAccessControl : System.Security.AccessControl.AccessControlSections -> System.Security.AccessControl.FileSecurity
    member IsReadOnly : bool with get, set
    member Length : int64
    member MoveTo : string -> unit
    member Name : string
    member Open : System.IO.FileMode -> System.IO.FileStream
    member Open : System.IO.FileMode * System.IO.FileAccess -> System.IO.FileStream
    member Open : System.IO.FileMode * System.IO.FileAccess * System.IO.FileShare -> System.IO.FileStream
    member OpenRead : unit -> System.IO.FileStream
    member OpenText : unit -> System.IO.StreamReader
    member OpenWrite : unit -> System.IO.FileStream
    member Replace : string * string -> System.IO.FileInfo
    member Replace : string * string * bool -> System.IO.FileInfo
    member SetAccessControl : System.Security.AccessControl.FileSecurity -> unit
    member ToString : unit -> string
  end

Full name: System.IO.FileInfo

  type: FileInfo
  implements: Runtime.Serialization.ISerializable
  inherits: FileSystemInfo
  inherits: MarshalByRefObject
property Option.IsSome: bool
val content : string

  type: string
  implements: IComparable
  implements: ICloneable
  implements: IConvertible
  implements: IComparable<string>
  implements: seq<char>
  implements: Collections.IEnumerable
  implements: IEquatable<string>
type File =
  class
    static member AppendAllLines : string * System.Collections.Generic.IEnumerable<string> -> unit
    static member AppendAllLines : string * System.Collections.Generic.IEnumerable<string> * System.Text.Encoding -> unit
    static member AppendAllText : string * string -> unit
    static member AppendAllText : string * string * System.Text.Encoding -> unit
    static member AppendText : string -> System.IO.StreamWriter
    static member Copy : string * string -> unit
    static member Copy : string * string * bool -> unit
    static member Create : string -> System.IO.FileStream
    static member Create : string * int -> System.IO.FileStream
    static member Create : string * int * System.IO.FileOptions -> System.IO.FileStream
    static member Create : string * int * System.IO.FileOptions * System.Security.AccessControl.FileSecurity -> System.IO.FileStream
    static member CreateText : string -> System.IO.StreamWriter
    static member Decrypt : string -> unit
    static member Delete : string -> unit
    static member Encrypt : string -> unit
    static member Exists : string -> bool
    static member GetAccessControl : string -> System.Security.AccessControl.FileSecurity
    static member GetAccessControl : string * System.Security.AccessControl.AccessControlSections -> System.Security.AccessControl.FileSecurity
    static member GetAttributes : string -> System.IO.FileAttributes
    static member GetCreationTime : string -> System.DateTime
    static member GetCreationTimeUtc : string -> System.DateTime
    static member GetLastAccessTime : string -> System.DateTime
    static member GetLastAccessTimeUtc : string -> System.DateTime
    static member GetLastWriteTime : string -> System.DateTime
    static member GetLastWriteTimeUtc : string -> System.DateTime
    static member Move : string * string -> unit
    static member Open : string * System.IO.FileMode -> System.IO.FileStream
    static member Open : string * System.IO.FileMode * System.IO.FileAccess -> System.IO.FileStream
    static member Open : string * System.IO.FileMode * System.IO.FileAccess * System.IO.FileShare -> System.IO.FileStream
    static member OpenRead : string -> System.IO.FileStream
    static member OpenText : string -> System.IO.StreamReader
    static member OpenWrite : string -> System.IO.FileStream
    static member ReadAllBytes : string -> System.Byte []
    static member ReadAllLines : string -> string []
    static member ReadAllLines : string * System.Text.Encoding -> string []
    static member ReadAllText : string -> string
    static member ReadAllText : string * System.Text.Encoding -> string
    static member ReadLines : string -> System.Collections.Generic.IEnumerable<string>
    static member ReadLines : string * System.Text.Encoding -> System.Collections.Generic.IEnumerable<string>
    static member Replace : string * string * string -> unit
    static member Replace : string * string * string * bool -> unit
    static member SetAccessControl : string * System.Security.AccessControl.FileSecurity -> unit
    static member SetAttributes : string * System.IO.FileAttributes -> unit
    static member SetCreationTime : string * System.DateTime -> unit
    static member SetCreationTimeUtc : string * System.DateTime -> unit
    static member SetLastAccessTime : string * System.DateTime -> unit
    static member SetLastAccessTimeUtc : string * System.DateTime -> unit
    static member SetLastWriteTime : string * System.DateTime -> unit
    static member SetLastWriteTimeUtc : string * System.DateTime -> unit
    static member WriteAllBytes : string * System.Byte [] -> unit
    static member WriteAllLines : string * string [] -> unit
    static member WriteAllLines : string * System.Collections.Generic.IEnumerable<string> -> unit
    static member WriteAllLines : string * string [] * System.Text.Encoding -> unit
    static member WriteAllLines : string * System.Collections.Generic.IEnumerable<string> * System.Text.Encoding -> unit
    static member WriteAllText : string * string -> unit
    static member WriteAllText : string * string * System.Text.Encoding -> unit
  end

Full name: System.IO.File
Multiple overloads
File.ReadAllText(path: string) : string
File.ReadAllText(path: string, encoding: Encoding) : string
property Option.Value: string
val matches : MatchCollection

  type: MatchCollection
  implements: Collections.ICollection
  implements: Collections.IEnumerable
type Regex =
  class
    new : string -> System.Text.RegularExpressions.Regex
    new : string * System.Text.RegularExpressions.RegexOptions -> System.Text.RegularExpressions.Regex
    member GetGroupNames : unit -> string []
    member GetGroupNumbers : unit -> int []
    member GroupNameFromNumber : int -> string
    member GroupNumberFromName : string -> int
    member IsMatch : string -> bool
    member IsMatch : string * int -> bool
    member Match : string -> System.Text.RegularExpressions.Match
    member Match : string * int -> System.Text.RegularExpressions.Match
    member Match : string * int * int -> System.Text.RegularExpressions.Match
    member Matches : string -> System.Text.RegularExpressions.MatchCollection
    member Matches : string * int -> System.Text.RegularExpressions.MatchCollection
    member Options : System.Text.RegularExpressions.RegexOptions
    member Replace : string * string -> string
    member Replace : string * System.Text.RegularExpressions.MatchEvaluator -> string
    member Replace : string * string * int -> string
    member Replace : string * System.Text.RegularExpressions.MatchEvaluator * int -> string
    member Replace : string * string * int * int -> string
    member Replace : string * System.Text.RegularExpressions.MatchEvaluator * int * int -> string
    member RightToLeft : bool
    member Split : string -> string []
    member Split : string * int -> string []
    member Split : string * int * int -> string []
    member ToString : unit -> string
    static member CacheSize : int with get, set
    static member CompileToAssembly : System.Text.RegularExpressions.RegexCompilationInfo [] * System.Reflection.AssemblyName -> unit
    static member CompileToAssembly : System.Text.RegularExpressions.RegexCompilationInfo [] * System.Reflection.AssemblyName * System.Reflection.Emit.CustomAttributeBuilder [] -> unit
    static member CompileToAssembly : System.Text.RegularExpressions.RegexCompilationInfo [] * System.Reflection.AssemblyName * System.Reflection.Emit.CustomAttributeBuilder [] * string -> unit
    static member Escape : string -> string
    static member IsMatch : string * string -> bool
    static member IsMatch : string * string * System.Text.RegularExpressions.RegexOptions -> bool
    static member Match : string * string -> System.Text.RegularExpressions.Match
    static member Match : string * string * System.Text.RegularExpressions.RegexOptions -> System.Text.RegularExpressions.Match
    static member Matches : string * string -> System.Text.RegularExpressions.MatchCollection
    static member Matches : string * string * System.Text.RegularExpressions.RegexOptions -> System.Text.RegularExpressions.MatchCollection
    static member Replace : string * string * string -> string
    static member Replace : string * string * System.Text.RegularExpressions.MatchEvaluator -> string
    static member Replace : string * string * string * System.Text.RegularExpressions.RegexOptions -> string
    static member Replace : string * string * System.Text.RegularExpressions.MatchEvaluator * System.Text.RegularExpressions.RegexOptions -> string
    static member Split : string * string -> string []
    static member Split : string * string * System.Text.RegularExpressions.RegexOptions -> string []
    static member Unescape : string -> string
  end

Full name: System.Text.RegularExpressions.Regex

  type: Regex
  implements: Runtime.Serialization.ISerializable
Multiple overloads
Regex.Matches(input: string, pattern: string) : MatchCollection
Regex.Matches(input: string, pattern: string, options: RegexOptions) : MatchCollection
Multiple items
val seq : seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Core.Operators.seq

--------------------

type seq<'T> = Collections.Generic.IEnumerable<'T>

Full name: Microsoft.FSharp.Collections.seq<_>

  type: seq<'T>
  inherits: Collections.IEnumerable
val m : Match

  type: Match
  inherits: Group
  inherits: Capture
property Match.Groups: GroupCollection
val map : ('T -> 'U) -> seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.map
val filename : string

  type: string
  implements: IComparable
  implements: ICloneable
  implements: IConvertible
  implements: IComparable<string>
  implements: seq<char>
  implements: Collections.IEnumerable
  implements: IEquatable<string>
val sprintf : Printf.StringFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
type String =
  class
    new : char -> string
    new : char * int * int -> string
    new : System.SByte -> string
    new : System.SByte * int * int -> string
    new : System.SByte * int * int * System.Text.Encoding -> string
    new : char [] * int * int -> string
    new : char [] -> string
    new : char * int -> string
    member Chars : int -> char
    member Clone : unit -> obj
    member CompareTo : obj -> int
    member CompareTo : string -> int
    member Contains : string -> bool
    member CopyTo : int * char [] * int * int -> unit
    member EndsWith : string -> bool
    member EndsWith : string * System.StringComparison -> bool
    member EndsWith : string * bool * System.Globalization.CultureInfo -> bool
    member Equals : obj -> bool
    member Equals : string -> bool
    member Equals : string * System.StringComparison -> bool
    member GetEnumerator : unit -> System.CharEnumerator
    member GetHashCode : unit -> int
    member GetTypeCode : unit -> System.TypeCode
    member IndexOf : char -> int
    member IndexOf : string -> int
    member IndexOf : char * int -> int
    member IndexOf : string * int -> int
    member IndexOf : string * System.StringComparison -> int
    member IndexOf : char * int * int -> int
    member IndexOf : string * int * int -> int
    member IndexOf : string * int * System.StringComparison -> int
    member IndexOf : string * int * int * System.StringComparison -> int
    member IndexOfAny : char [] -> int
    member IndexOfAny : char [] * int -> int
    member IndexOfAny : char [] * int * int -> int
    member Insert : int * string -> string
    member IsNormalized : unit -> bool
    member IsNormalized : System.Text.NormalizationForm -> bool
    member LastIndexOf : char -> int
    member LastIndexOf : string -> int
    member LastIndexOf : char * int -> int
    member LastIndexOf : string * int -> int
    member LastIndexOf : string * System.StringComparison -> int
    member LastIndexOf : char * int * int -> int
    member LastIndexOf : string * int * int -> int
    member LastIndexOf : string * int * System.StringComparison -> int
    member LastIndexOf : string * int * int * System.StringComparison -> int
    member LastIndexOfAny : char [] -> int
    member LastIndexOfAny : char [] * int -> int
    member LastIndexOfAny : char [] * int * int -> int
    member Length : int
    member Normalize : unit -> string
    member Normalize : System.Text.NormalizationForm -> string
    member PadLeft : int -> string
    member PadLeft : int * char -> string
    member PadRight : int -> string
    member PadRight : int * char -> string
    member Remove : int -> string
    member Remove : int * int -> string
    member Replace : char * char -> string
    member Replace : string * string -> string
    member Split : char [] -> string []
    member Split : char [] * int -> string []
    member Split : char [] * System.StringSplitOptions -> string []
    member Split : string [] * System.StringSplitOptions -> string []
    member Split : char [] * int * System.StringSplitOptions -> string []
    member Split : string [] * int * System.StringSplitOptions -> string []
    member StartsWith : string -> bool
    member StartsWith : string * System.StringComparison -> bool
    member StartsWith : string * bool * System.Globalization.CultureInfo -> bool
    member Substring : int -> string
    member Substring : int * int -> string
    member ToCharArray : unit -> char []
    member ToCharArray : int * int -> char []
    member ToLower : unit -> string
    member ToLower : System.Globalization.CultureInfo -> string
    member ToLowerInvariant : unit -> string
    member ToString : unit -> string
    member ToString : System.IFormatProvider -> string
    member ToUpper : unit -> string
    member ToUpper : System.Globalization.CultureInfo -> string
    member ToUpperInvariant : unit -> string
    member Trim : unit -> string
    member Trim : char [] -> string
    member TrimEnd : char [] -> string
    member TrimStart : char [] -> string
    static val Empty : string
    static member Compare : string * string -> int
    static member Compare : string * string * bool -> int
    static member Compare : string * string * System.StringComparison -> int
    static member Compare : string * string * System.Globalization.CultureInfo * System.Globalization.CompareOptions -> int
    static member Compare : string * string * bool * System.Globalization.CultureInfo -> int
    static member Compare : string * int * string * int * int -> int
    static member Compare : string * int * string * int * int * bool -> int
    static member Compare : string * int * string * int * int * System.StringComparison -> int
    static member Compare : string * int * string * int * int * bool * System.Globalization.CultureInfo -> int
    static member Compare : string * int * string * int * int * System.Globalization.CultureInfo * System.Globalization.CompareOptions -> int
    static member CompareOrdinal : string * string -> int
    static member CompareOrdinal : string * int * string * int * int -> int
    static member Concat : obj -> string
    static member Concat : obj [] -> string
    static member Concat<'T> : System.Collections.Generic.IEnumerable<'T> -> string
    static member Concat : System.Collections.Generic.IEnumerable<string> -> string
    static member Concat : string [] -> string
    static member Concat : obj * obj -> string
    static member Concat : string * string -> string
    static member Concat : obj * obj * obj -> string
    static member Concat : string * string * string -> string
    static member Concat : obj * obj * obj * obj -> string
    static member Concat : string * string * string * string -> string
    static member Copy : string -> string
    static member Equals : string * string -> bool
    static member Equals : string * string * System.StringComparison -> bool
    static member Format : string * obj -> string
    static member Format : string * obj [] -> string
    static member Format : string * obj * obj -> string
    static member Format : System.IFormatProvider * string * obj [] -> string
    static member Format : string * obj * obj * obj -> string
    static member Intern : string -> string
    static member IsInterned : string -> string
    static member IsNullOrEmpty : string -> bool
    static member IsNullOrWhiteSpace : string -> bool
    static member Join : string * string [] -> string
    static member Join : string * obj [] -> string
    static member Join<'T> : string * System.Collections.Generic.IEnumerable<'T> -> string
    static member Join : string * System.Collections.Generic.IEnumerable<string> -> string
    static member Join : string * string [] * int * int -> string
  end

Full name: System.String

  type: String
  implements: IComparable
  implements: ICloneable
  implements: IConvertible
  implements: IComparable<string>
  implements: seq<char>
  implements: Collections.IEnumerable
  implements: IEquatable<string>
val concat : string -> seq<string> -> string

Full name: Microsoft.FSharp.Core.String.concat
val failwith : string -> 'T

Full name: Microsoft.FSharp.Core.Operators.failwith
namespace System.Windows
namespace System.Windows.Forms
type Clipboard =
  class
    static member Clear : unit -> unit
    static member ContainsAudio : unit -> bool
    static member ContainsData : string -> bool
    static member ContainsFileDropList : unit -> bool
    static member ContainsImage : unit -> bool
    static member ContainsText : unit -> bool
    static member ContainsText : System.Windows.Forms.TextDataFormat -> bool
    static member GetAudioStream : unit -> System.IO.Stream
    static member GetData : string -> obj
    static member GetDataObject : unit -> System.Windows.Forms.IDataObject
    static member GetFileDropList : unit -> System.Collections.Specialized.StringCollection
    static member GetImage : unit -> System.Drawing.Image
    static member GetText : unit -> string
    static member GetText : System.Windows.Forms.TextDataFormat -> string
    static member SetAudio : System.Byte [] -> unit
    static member SetAudio : System.IO.Stream -> unit
    static member SetData : string * obj -> unit
    static member SetDataObject : obj -> unit
    static member SetDataObject : obj * bool -> unit
    static member SetDataObject : obj * bool * int * int -> unit
    static member SetFileDropList : System.Collections.Specialized.StringCollection -> unit
    static member SetImage : System.Drawing.Image -> unit
    static member SetText : string -> unit
    static member SetText : string * System.Windows.Forms.TextDataFormat -> unit
  end

Full name: System.Windows.Forms.Clipboard
Multiple overloads
Windows.Forms.Clipboard.SetText(text: string) : unit
Windows.Forms.Clipboard.SetText(text: string, format: Windows.Forms.TextDataFormat) : unit

More information

Link: http://fssnip.net/a2
Posted: 2 years ago
Author: nagat01 (website)
Tags: Scripting, Input and Output, Parsing