Class FileClientUtils
This class provides useful helper method when using files
Inheritance
System.Object
FileClientUtils
Assembly: Mars.IO.dll
Syntax
public static class FileClientUtils : object
Methods
Extract the specified file into an in-memory zip archive
Declaration
public static void ExtractAsZipArchive(this string filename, Action<ZipArchive> access)
Parameters
Type |
Name |
Description |
System.String |
filename |
The to extract into an in-memory zip-archive |
Action<ZipArchive> |
access |
The access body within the opened file scope. |
Extracts the gzip file at the into the temporary file path of the current user.
Declaration
public static string ExtractGzip(this string filename)
Parameters
Type |
Name |
Description |
System.String |
filename |
The gzip file path (*.gz) |
Returns
Type |
Description |
System.String |
Returns the full path of the directory where all the content were extracted. |
Extracts the zip file at the into the desired directory and creates a subfolder therein
When no extractAt
directory path was assigned the temp file path of the user will be used instead.
Declaration
public static string ExtractZip(this string filename, string extractAt = null)
Parameters
Type |
Name |
Description |
System.String |
filename |
The zip file path |
System.String |
extractAt |
The extraction directory where to save the content of the zip file |
Returns
Type |
Description |
System.String |
|
IsFileLocked(IFileInfo)
Checks whether the specified file is currently used and therefore locked by another process.
Ths method can be used in order to synchronize the access on a single "file" source. A good approach
would be to wait until the file has been released with a limited amount of retries.
int retries = 10
while(file.IsFileLocked retries > 0) { Thread.Sleep(100); retries--; }
Declaration
public static bool IsFileLocked(this IFileInfo file)
Parameters
Type |
Name |
Description |
IFileInfo |
file |
The file to check for the concurrent access |
Returns
Type |
Description |
System.Boolean |
Returns true, when the file is currently be used |
IsValidFile(String)
Short form to check whether a file path string is valid and the file exist
Declaration
public static bool IsValidFile(this string file)
Parameters
Type |
Name |
Description |
System.String |
file |
|
Returns
Type |
Description |
System.Boolean |
|
RelativePathTo(String)
Creates a relative path from one file or folder to another.
Declaration
public static string RelativePathTo(this string toPath)
Parameters
Type |
Name |
Description |
System.String |
toPath |
Contains the path that defines the endpoint of the relative path. |
Returns
Type |
Description |
System.String |
The relative path from the start directory to the end path. |