Class FileUtility
A utility class to do file operations.
Namespace: Unity.AnimeToolbox
Syntax
public static class FileUtility
Methods
ComputeFileMD5(String)
Compute the MD5 hash code of a file
Declaration
public static string ComputeFileMD5(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| String | path | The path to file |
Returns
| Type | Description |
|---|---|
| String | The MD5 hash code of the file |
CopyRecursive(String, String, Boolean)
Copy a directory to another directory recursively
Declaration
public static void CopyRecursive(string sourceDir, string targetDir, bool overwrite)
Parameters
| Type | Name | Description |
|---|---|---|
| String | sourceDir | The source directory |
| String | targetDir | The target directory |
| Boolean | overwrite | true if the destination file can be overwritten; otherwise, false. |
DeleteFilesAndFolders(DirectoryInfo)
Delete files and folders under the passed directory
Declaration
public static bool DeleteFilesAndFolders(DirectoryInfo di)
Parameters
| Type | Name | Description |
|---|---|---|
| DirectoryInfo | di | The DirectoryInfo of the directory to be deleted |
Returns
| Type | Description |
|---|---|
| Boolean | True if deletion is successful, false otherwise |
DeleteFilesAndFolders(String)
Delete files and folders under the passed directory
Declaration
public static bool DeleteFilesAndFolders(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| String | path | The path to directory to be deleted |
Returns
| Type | Description |
|---|---|
| Boolean | True if deletion is successful, false otherwise |
DeserializeFromJson<T>(String)
Deserialize a json file to an object
Declaration
public static T DeserializeFromJson<T>(string path)
where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| String | path | The path to the json file |
Returns
| Type | Description |
|---|---|
| T | The deserialized object with type T |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the object inside the json file |
MakeFileWritable(String)
Make file writable
Declaration
public static bool MakeFileWritable(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| String | path | The path to the file |
Returns
| Type | Description |
|---|---|
| Boolean | The file could be made writable or not |
SerializeToJson<T>(T, String, Boolean)
Serializes an object into a json file
Declaration
public static void SerializeToJson<T>(T obj, string path, bool prettyPrint = false)
Parameters
| Type | Name | Description |
|---|---|---|
| T | obj | The object to be serialized |
| String | path | The path to the json file |
| Boolean | prettyPrint | If true, format the output for readability. If false, format the output for minimum size. Default is false. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the object |