C# Class Nexus.Client.Util.FileUtil

Utility functions to work with files.
显示文件 Open project: NexusMods/NexusModManager-4.5 Class Usage Examples

Public Methods

Method Description
ClearAttributes ( DirectoryInfo p_difPath, bool p_booRecurse ) : void

Clears the attributes of the given directory.

This sets the directory's attributes to FileAttributes.Normal. This operation is optionally recursive.

ClearAttributes ( string p_strPath, bool p_booRecurse ) : void

Clears the attributes of the given path.

This sets the path's attributes to FileAttributes.Normal. This operation is optionally recursive.

ContainsInvalidPathChars ( string p_strPath ) : bool

Determines if the given path contains invalid characters.

Copy ( TxFileManager p_tfmFileManager, string p_strSource, string p_strDestination, bool>.Func p_fncCopyCallback ) : bool

Copies the source to the destination.

If the source is a directory, it is copied recursively.

Copy ( string p_strSource, string p_strDestination, bool>.Func p_fncCopyCallback ) : bool

Copies the source to the destination.

If the source is a directory, it is copied recursively.

CreateTempDirectory ( ) : string

Creates a temporary directory.

ForceDelete ( string p_strPath ) : void

Forces deletion of the given path.

This method is recursive if the given path is a directory. This method will clear read only/system attributes if required to delete the path.

IsDrivePath ( string p_strPath ) : bool

Determines whether or not the given path represents a drive.

IsValidPath ( string p_strPath ) : bool

Determines if the given path is valid.

Move ( string p_strFrom, string p_strTo, bool p_booOverwrite ) : void

Moves the specified file to the specified path, optionally overwritting any existing file.

NormalizePath ( string p_strPath ) : string

Normalizes the given path.

This removes multiple consecutive path separators and makes sure all path separators are Path.DirectorySeparatorChar.

RelativizePath ( string p_strRoot, string p_strPath ) : string

Generates a path that is relative to another path.

StripInvalidPathChars ( string p_strPath ) : string

Removes all invalid characters from the given path.

WriteAllBytes ( string p_strPath, byte p_bteData ) : void

Writes the given data to the specified file.

If the specified file exists, it will be overwritten. If the specified file does not exist, it is created. If the directory containing the specified file does not exist, it is created.

WriteAllText ( string p_strPath, string p_strData ) : void

Writes the given data to the specified file.

If the specified file exists, it will be overwritten. If the specified file does not exist, it is created. If the directory containing the specified file does not exist, it is created.

Protected Methods

Method Description
CreateTempDirectory ( string p_strBasePath ) : string

Creates a temporary directory rooted at the given path.

Method Details

ClearAttributes() public static method

Clears the attributes of the given directory.
This sets the directory's attributes to FileAttributes.Normal. This operation is optionally recursive.
public static ClearAttributes ( DirectoryInfo p_difPath, bool p_booRecurse ) : void
p_difPath System.IO.DirectoryInfo The directory whose attributes are to be cleared.
p_booRecurse bool Whether or not to clear the attributes on all children files and folers.
return void

ClearAttributes() public static method

Clears the attributes of the given path.
This sets the path's attributes to FileAttributes.Normal. This operation is optionally recursive.
public static ClearAttributes ( string p_strPath, bool p_booRecurse ) : void
p_strPath string The path whose attributes are to be cleared.
p_booRecurse bool Whether or not to clear the attributes on all children files and folers.
return void

ContainsInvalidPathChars() public static method

Determines if the given path contains invalid characters.
public static ContainsInvalidPathChars ( string p_strPath ) : bool
p_strPath string The path to examine.
return bool

Copy() public static method

Copies the source to the destination.
If the source is a directory, it is copied recursively.
public static Copy ( TxFileManager p_tfmFileManager, string p_strSource, string p_strDestination, bool>.Func p_fncCopyCallback ) : bool
p_tfmFileManager ChinhDo.Transactions.TxFileManager The transactional file manager to use to copy the files.
p_strSource string The path from which to copy.
p_strDestination string The path to which to copy.
p_fncCopyCallback bool>.Func A callback method that notifies the caller when a file has been copied, /// and provides the opportunity to cancel the copy operation.
return bool

Copy() public static method

Copies the source to the destination.
If the source is a directory, it is copied recursively.
public static Copy ( string p_strSource, string p_strDestination, bool>.Func p_fncCopyCallback ) : bool
p_strSource string The path from which to copy.
p_strDestination string The path to which to copy.
p_fncCopyCallback bool>.Func A callback method that notifies the caller when a file has been copied, /// and provides the opportunity to cancel the copy operation.
return bool

CreateTempDirectory() public method

Creates a temporary directory.
public CreateTempDirectory ( ) : string
return string

CreateTempDirectory() protected method

Creates a temporary directory rooted at the given path.
protected CreateTempDirectory ( string p_strBasePath ) : string
p_strBasePath string The path under which to create the temporary directory.
return string

ForceDelete() public static method

Forces deletion of the given path.
This method is recursive if the given path is a directory. This method will clear read only/system attributes if required to delete the path.
public static ForceDelete ( string p_strPath ) : void
p_strPath string The path to delete.
return void

IsDrivePath() public static method

Determines whether or not the given path represents a drive.
public static IsDrivePath ( string p_strPath ) : bool
p_strPath string The path for which it is to be determine whether it represents a drive.
return bool

IsValidPath() public static method

Determines if the given path is valid.
public static IsValidPath ( string p_strPath ) : bool
p_strPath string The path to examine.
return bool

Move() public static method

Moves the specified file to the specified path, optionally overwritting any existing file.
public static Move ( string p_strFrom, string p_strTo, bool p_booOverwrite ) : void
p_strFrom string The path to the file to move.
p_strTo string the path to which to move the file.
p_booOverwrite bool Whether to overwrite any file found at the destination.
return void

NormalizePath() public static method

Normalizes the given path.
This removes multiple consecutive path separators and makes sure all path separators are Path.DirectorySeparatorChar.
public static NormalizePath ( string p_strPath ) : string
p_strPath string The path to normalize.
return string

RelativizePath() public static method

Generates a path that is relative to another path.
Thrown if either parameter is null.
public static RelativizePath ( string p_strRoot, string p_strPath ) : string
p_strRoot string The root directory with respect to which the path will be made relative.
p_strPath string The path to make relative.
return string

StripInvalidPathChars() public static method

Removes all invalid characters from the given path.
public static StripInvalidPathChars ( string p_strPath ) : string
p_strPath string The path to clean.
return string

WriteAllBytes() public static method

Writes the given data to the specified file.
If the specified file exists, it will be overwritten. If the specified file does not exist, it is created. If the directory containing the specified file does not exist, it is created.
public static WriteAllBytes ( string p_strPath, byte p_bteData ) : void
p_strPath string The path to which to write the given data.
p_bteData byte The data to write to the file.
return void

WriteAllText() public static method

Writes the given data to the specified file.
If the specified file exists, it will be overwritten. If the specified file does not exist, it is created. If the directory containing the specified file does not exist, it is created.
public static WriteAllText ( string p_strPath, string p_strData ) : void
p_strPath string The path to which to write the given text.
p_strData string The text to write to the file.
return void