Table of Contents

Class FileUtil

Namespace
Hi.Common.FileLines
Assembly
HiGeom.dll

Utility to manage files.

public static class FileUtil
Inheritance
FileUtil
Inherited Members

Methods

CopyDirectory(string, string)

Copies a directory and all its contents to a destination folder.

public static void CopyDirectory(string sourceFolder, string destFolder)

Parameters

sourceFolder string

Source directory path

destFolder string

Destination directory path

CreateWithDirectoryAndGetFileStream(string)

Creates or loads a file with directory.

public static FileStream CreateWithDirectoryAndGetFileStream(string filePath)

Parameters

filePath string

file path

Returns

FileStream

file stream

CreateWithDirectoryIfNotExisted(string)

public static bool CreateWithDirectoryIfNotExisted(string filePath)

Parameters

filePath string

Returns

bool

true if file created.

EnsureDirectory(string)

Ensures that the specified directory exists, creating it if necessary.

public static void EnsureDirectory(string directory)

Parameters

directory string

The directory path to ensure exists.

GetAbsentPath(string, string)

Gets a path that doesn't exist by appending a number to the base path.

public static string GetAbsentPath(string pathWithoutExtension, string extension)

Parameters

pathWithoutExtension string

The base path without extension.

extension string

The file extension.

Returns

string

A path that doesn't exist.

GetAbsentRelPath(string, string, string)

Gets a relative path that doesn't exist by appending a number to the base path.

public static string GetAbsentRelPath(string baseDirectory, string relPathWithoutExtension, string extension)

Parameters

baseDirectory string

The base directory.

relPathWithoutExtension string

The relative path without extension.

extension string

The file extension.

Returns

string

A relative path that doesn't exist.

GetDescendentPath(string)

Get descendent path if the path is descendent of current path; otherwise return path.

public static string GetDescendentPath(string path)

Parameters

path string

path

Returns

string

descendent path if the path is descendent of current path; otherwise return path

GetFileSizeString(FileInfo, string)

Gets a formatted string representing the file size.

public static string GetFileSizeString(this FileInfo fileInfo, string format = "{0,6:###.00} {1,-2:##}")

Parameters

fileInfo FileInfo

The file information.

format string

The format string to use.

Returns

string

A formatted string representing the file size.

IsBinaryFile(string)

Determines if a file is likely to be a binary file by checking for control characters.

public static bool IsBinaryFile(string filePath)

Parameters

filePath string

Path to the file to check

Returns

bool

True if the file appears to be binary, false otherwise

ReadAllTextWithFileShareAsync(string)

Reads all text from a file with file sharing enabled.

public static Task<string> ReadAllTextWithFileShareAsync(string filePath)

Parameters

filePath string

The path of the file to read.

Returns

Task<string>

A task that represents the asynchronous read operation, which wraps the file contents.

ToIndexedFile(IEnumerable<string>)

Converts a collection of file paths to a collection of indexed files.

public static IEnumerable<IndexedFile> ToIndexedFile(this IEnumerable<string> files)

Parameters

files IEnumerable<string>

The collection of file paths.

Returns

IEnumerable<IndexedFile>

A collection of indexed files.