<commit_before>﻿[<AutoOpen>]
/// Contains helpers which allow to interact with the file system.
module Fake.FileSystemHelper

open System
open System.Text
open System.IO
open System.Runtime.InteropServices

/// Creates a DirectoryInfo for the given path.
let inline directoryInfo path = new DirectoryInfo(path)

/// Creates a FileInfo for the given path.
let inline fileInfo path = new FileInfo(path)

/// Creates a FileInfo or a DirectoryInfo for the given path
let inline fileSystemInfo path : FileSystemInfo = 
    if Directory.Exists path then upcast directoryInfo path
    else upcast fileInfo path

/// Converts a filename to it's full file system name.
let inline FullName fileName = Path.GetFullPath fileName

/// Gets the directory part of a filename.
let inline DirectoryName fileName = Path.GetDirectoryName fileName

/// Gets all subdirectories of a given directory.
let inline subDirectories (dir : DirectoryInfo) = dir.GetDirectories()

/// Gets all files in the directory.
let inline filesInDir (dir : DirectoryInfo) = dir.GetFiles()

/// Finds all the files in the directory matching the search pattern.
let filesInDirMatching pattern (dir : DirectoryInfo) = 
    if dir.Exists then dir.GetFiles pattern
    else [||]

/// Gets the first file in the directory matching the search pattern as an option value.
let TryFindFirstMatchingFile pattern dir = 
    dir<commit_msg>Search for files with a given pattern also in subdirectories<commit_after>﻿[<AutoOpen>]
/// Contains helpers which allow to interact with the file system.
module Fake.FileSystemHelper

open System
open System.Text
open System.IO
open System.Runtime.InteropServices

/// Creates a DirectoryInfo for the given path.
let inline directoryInfo path = new DirectoryInfo(path)

/// Creates a FileInfo for the given path.
let inline fileInfo path = new FileInfo(path)

/// Creates a FileInfo or a DirectoryInfo for the given path
let inline fileSystemInfo path : FileSystemInfo = 
    if Directory.Exists path then upcast directoryInfo path
    else upcast fileInfo path

/// Converts a filename to it's full file system name.
let inline FullName fileName = Path.GetFullPath fileName

/// Gets the directory part of a filename.
let inline DirectoryName fileName = Path.GetDirectoryName fileName

/// Gets all subdirectories of a given directory.
let inline subDirectories (dir : DirectoryInfo) = dir.GetDirectories()

/// Gets all files in the directory.
let inline filesInDir (dir : DirectoryInfo) = dir.GetFiles()

/// Finds all the files in the directory matching the search pattern.
let filesInDirMatching pattern (dir : DirectoryInfo) = 
    if dir.Exists then dir.GetFiles pattern
    else [||]
    
/// Finds all the files in the directory and in all subdirectories matching the search pattern.
let filesInDirMatchingRecursive pattern (dir : DirectoryInfo) = 
    if dir.Exists then dir.GetFiles(pattern, SearchOption.AllDirectories)
    else [||]    

/// Gets the first file in the directory matching the search pattern as an option value.
let TryFindFirstMatchingFile pattern dir = 
    dir
{'fraction_non_alphanumeric': 0.06495615459564794, 'fraction_numerical': 0.0, 'mean_word_length': 4.008130081300813, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7373320', 'n_tokens_mistral': 811, 'n_tokens_neox': 792, 'n_words': 370}