Note: This is the migration API reference for FAKE 5. The new (modularized) API documentation can be found here. If the API is already migrated you can check here if exists in a module. More information regarding the migration can be found here

File

Functions and values

Function or valueDescription
File.allExist(files)
Signature: files:seq<string> -> bool

Checks if all given files exist.

File.append file lines
Signature: file:string -> lines:seq<string> -> unit

Appends all lines to a file line by line

File.applyReplace replaceF fileName
Signature: replaceF:(string -> string) -> fileName:string -> unit

Replaces the text in the given file

File.checkExists(fileName)
Signature: fileName:string -> unit

Raises an exception if the file doesn't exist on disk.

File.create(fileName)
Signature: fileName:string -> unit

Creates a file if it does not exist.

File.delete(fileName)
Signature: fileName:string -> unit

Deletes a file if it exists.

File.deleteAll(files)
Signature: files:seq<string> -> unit

Deletes the given files.

File.exists(fileName)
Signature: fileName:string -> bool

Checks if the file exists on disk.

File.getEncoding def filename
Signature: def:Encoding -> filename:string -> Encoding
File.getEncodingOrDefault def filename
Signature: def:Encoding -> filename:string -> Encoding

Gets the encoding from the file or the default of the file doesn't exist

File.getEncodingOrUtf8WithoutBom
Signature: string -> Encoding

Get the encoding from the file or utf8 without BOM if unknown or the file doesn't exist

File.getVersion(fileName)
Signature: fileName:string -> string

Get the version a file. This overload throws when the file has no version, consider using tryGetVersion instead. On non-windows platforms this API returns assembly metadata instead, see https://github.com/dotnet/corefx/blob/5fb98a118bb19a91e8ffb5c17ff5e7c00a4c05ee/src/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Unix.cs#L20-L28

Parameters

  • 'fileName' - Name of file from which the version is retrieved. The path can be relative.
File.read(file)
Signature: file:string -> seq<string>
File.readAsBytes(file)
Signature: file:string -> byte []

Reads a file as one array of bytes

File.readAsString(file)
Signature: file:string -> string
File.readAsStringWithEncoding(...)
Signature: encoding:Encoding -> file:string -> string

Reads a file as one text

File.readLine(file)
Signature: file:string -> string

Reads the first line of a file. This can be helpful to read a password from file.

File.readLineWithEncoding encoding file
Signature: encoding:Encoding -> file:string -> string

Reads the first line of a file. This can be helpful to read a password from file.

File.readWithEncoding encoding file
Signature: encoding:Encoding -> file:string -> seq<string>

Reads a file line by line

File.replaceContent fileName text
Signature: fileName:string -> text:string -> unit

Replaces the file with the given string

File.tryGetVersion(fileName)
Signature: fileName:string -> string option

Tries to get the version a file. Throws FileNotFoundException if the file doesn't exist. Returns None if the file doesn't contain a FileVersion component. On non-windows platforms this API returns assembly metadata instead, see https://github.com/dotnet/corefx/blob/5fb98a118bb19a91e8ffb5c17ff5e7c00a4c05ee/src/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Unix.cs#L20-L28

Parameters

  • 'fileName' - Name of file from which the version is retrieved. The path can be relative.
File.write append fileName lines
Signature: append:bool -> fileName:string -> lines:seq<string> -> unit
File.writeBytes file bytes
Signature: file:string -> bytes:byte [] -> unit

Writes a byte array to a file

File.writeNew file lines
Signature: file:string -> lines:seq<string> -> unit

Writes a file line by line

File.writeString append fileName text
Signature: append:bool -> fileName:string -> text:string -> unit
File.writeStringWithEncoding(...)
Signature: encoding:Encoding -> append:bool -> fileName:string -> text:string -> unit

Writes a string to a file

File.writeWithEncoding(...)
Signature: encoding:Encoding -> append:bool -> fileName:string -> lines:seq<string> -> unit

Writes a file line by line

Active patterns

Active patternDescription
File.( |EndsWith|_| ) extension file
Signature: extension:string -> file:string -> unit option

Active Pattern for determining file extension.