1 people like it.

Are Files Present In A Directory?

A quick and dirty function to check to see if there are files present in a directory. Note this will return false if there are only subdirs in a directory.

1: 
2: 
3: 
4: 
open System.IO

let AreFilesPresentInDirectory dir = 
    (Directory.EnumerateFileSystemEntries(dir) |> Seq.length) > (Directory.GetDirectories(dir) |> Seq.length)
namespace System
namespace System.IO
val AreFilesPresentInDirectory : dir:string -> bool

Full name: Script.AreFilesPresentInDirectory
val dir : string
type Directory =
  static member CreateDirectory : path:string -> DirectoryInfo + 1 overload
  static member Delete : path:string -> unit + 1 overload
  static member EnumerateDirectories : path:string -> IEnumerable<string> + 2 overloads
  static member EnumerateFileSystemEntries : path:string -> IEnumerable<string> + 2 overloads
  static member EnumerateFiles : path:string -> IEnumerable<string> + 2 overloads
  static member Exists : path:string -> bool
  static member GetAccessControl : path:string -> DirectorySecurity + 1 overload
  static member GetCreationTime : path:string -> DateTime
  static member GetCreationTimeUtc : path:string -> DateTime
  static member GetCurrentDirectory : unit -> string
  ...

Full name: System.IO.Directory
Directory.EnumerateFileSystemEntries(path: string) : System.Collections.Generic.IEnumerable<string>
Directory.EnumerateFileSystemEntries(path: string, searchPattern: string) : System.Collections.Generic.IEnumerable<string>
Directory.EnumerateFileSystemEntries(path: string, searchPattern: string, searchOption: SearchOption) : System.Collections.Generic.IEnumerable<string>
module Seq

from Microsoft.FSharp.Collections
val length : source:seq<'T> -> int

Full name: Microsoft.FSharp.Collections.Seq.length
Directory.GetDirectories(path: string) : string []
Directory.GetDirectories(path: string, searchPattern: string) : string []
Directory.GetDirectories(path: string, searchPattern: string, searchOption: SearchOption) : string []

More information

Link:http://fssnip.net/kM
Posted:11 years ago
Author:Onorio Catenacci
Tags: files , io , utility