Class FileClientUtils
This class provides useful helper method when using files
Inheritance
System.Object
FileClientUtils
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Mars.Common.IO
Assembly: Mars.IO.dll
Syntax
public static class FileClientUtils
Methods
| Improve this Doc View SourceExtractAsZipArchive(String, Action<ZipArchive>)
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 |
System.Action<System.IO.Compression.ZipArchive> | access | The access body within the opened file scope. |
ExtractGzip(String)
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. |
Exceptions
Type | Condition |
---|---|
System.IO.FileNotFoundException | The zip file does not exists |
ExtractZip(String, String)
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 |
Exceptions
Type | Condition |
---|---|
System.IO.FileNotFoundException | The zip file does not exists |
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 |
---|---|---|
System.IO.Abstractions.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. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Occurs when the toPath is NULL |