Table of contents
TOC
Collapse the table of content
Expand the table of content

ExtraTopLevelOperators.fprintfn<'T> Function (F#)

Den Delimarsky|Last Updated: 7/5/2016
|
1 Contributor

The fprintfn prints to a file using the given format, and add a newline.

Namespace/Module Path: Microsoft.FSharp.Core.ExtraTopLevelOperators

Assembly: FSharp.Core (in FSharp.Core.dll)

Syntax

// Signature:
fprintfn : TextWriter -> TextWriterFormat<'T> -> 'T

// Usage:
fprintfn textWriter format

Parameters

textWriter Type: System.IO.TextWriter

format Type: TextWriterFormat<'T>

Remarks

This function is named PrintFormatLineToTextWriter in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.

Example

The following example demonstrates the use of fprintfn to print a listing of the contents of a directory to a specified file, directorylisting.txt.


    let fileName = "directoryListing.txt"
    let printDirectoryInfo (dirName:string) (fileName:string) =
        use file = System.IO.File.CreateText(fileName)
        System.IO.Directory.EnumerateFileSystemEntries(dirName)
        |> Seq.iter (fun elem -> fprintfn file "%s" elem )
    printDirectoryInfo @"C:\" fileName
    printfn "%s" (System.IO.File.OpenText(fileName).ReadToEnd())

    let fileName = "directoryListingXY.txt"
    let printDirectoryInfo (dirName:string) (fileName:string) =
        use file = System.IO.File.CreateText(fileName)
        System.IO.Directory.EnumerateDirectories(dirName)
        |> Seq.map (fun elem -> new System.IO.DirectoryInfo(elem))
        |> Seq.iter (fun elem -> fprintfn file "%50s %A" elem.FullName elem.LastAccessTime )
        System.IO.Directory.EnumerateFiles(dirName)
        |> Seq.map (fun elem -> new System.IO.FileInfo(elem))
        |> Seq.iter (fun elem -> fprintfn file "%50s %A" elem.FullName elem.LastAccessTime )
    printDirectoryInfo @"C:\" fileName
    printfn "%s" (System.IO.File.OpenText(fileName).ReadToEnd())

Platforms

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Core.ExtraTopLevelOperators Module (F#)

Microsoft.FSharp.Core Namespace (F#)

© 2016 Microsoft