Class ReadWrite
Read write static methods.
讀寫的靜態方法。
Inheritance
Namespace: Votanic
Assembly: Votanic.Core.dll
Syntax
public class ReadWrite
Methods
CreateDirectory(String)
Create a directory.
創建一個目錄。
CreateDirectory("C:/abc/efg");
Declaration
public static void CreateDirectory(string directory)
Parameters
Type | Name | Description |
---|---|---|
System.String | directory | Target location |
DeleteDirectory(String, Boolean)
Delete an existed directory.
刪除一個存在的目錄。
DeleteDirectory("C:/abc/efg");
Declaration
public static void DeleteDirectory(string directory, bool recursive)
Parameters
Type | Name | Description |
---|---|---|
System.String | directory | Target location |
System.Boolean | recursive | Delete subdirectories if ture |
DirectoryCount(String, SearchOption, String[])
Get directory infos from a path.
由路經取得目錄資訊。
DirectoryInfo[] directories = DirectoryCount("C:/abc/efg/", SearchOption.AllDirectories, "xyz")
Declaration
public static DirectoryInfo[] DirectoryCount(string path, SearchOption searchOption = SearchOption.AllDirectories, params string[] searchPattern)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Target location |
System.IO.SearchOption | searchOption | Search option |
System.String[] | searchPattern | Pattern of file name |
Returns
Type | Description |
---|---|
System.IO.DirectoryInfo[] |
DirectoryExists(String)
Return true if the directory exists.
當目錄存在時傳回 true。
if (DirectoryExists("C:/abc/efg")) ...
Declaration
public static bool DirectoryExists(string directory)
Parameters
Type | Name | Description |
---|---|---|
System.String | directory | Target location |
Returns
Type | Description |
---|---|
System.Boolean |
DirectoryName(String)
Return the directory of a path.
傳回路經的目錄。
DirectoryName("C:/abc/efg/text.txt")
Declaration
public static string DirectoryName(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Target location |
Returns
Type | Description |
---|---|
System.String |
Extension(String)
Return the extension of a path.
傳回路經的副檔名。
Extension("C:/abc/efg/text.txt")
Declaration
public static string Extension(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Target location |
Returns
Type | Description |
---|---|
System.String |
FileCount(String, SearchOption, String[])
Get file infos from a path.
由路經取得檔案資訊。
FileInfo[] files = FileCount("C:/abc/efg/", SearchOption.AllDirectories, "*.txt")
Declaration
public static FileInfo[] FileCount(string path, SearchOption searchOption = SearchOption.AllDirectories, params string[] searchPattern)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Target location |
System.IO.SearchOption | searchOption | Search option |
System.String[] | searchPattern | Pattern of file name |
Returns
Type | Description |
---|---|
System.IO.FileInfo[] |
FileExists(String)
Return true if the file exists.
當檔案存在時傳回 true。
if (FileExists("C:/abc/efg/text.txt")) ...
Declaration
public static bool FileExists(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Target file |
Returns
Type | Description |
---|---|
System.Boolean |
FileName(String, Boolean)
Return the file name of a path.
傳回路經的檔案名稱。
FileName("C:/abc/efg/text.txt")
Declaration
public static string FileName(string path, bool extension = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Target location |
System.Boolean | extension | Return with extension if true |
Returns
Type | Description |
---|---|
System.String |
FullPath(String)
Return the full name of a path.
傳回路經的全名。
FullPath("C:/abc/efg/text.txt")
Declaration
public static string FullPath(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Target location |
Returns
Type | Description |
---|---|
System.String |
FullPathToArray(String)
Return the directory, file name and extension of a path.
傳回路經的目錄、檔案名稱及副檔名。
FullPathToArray("C:/abc/efg/text.txt")
Declaration
public static string[] FullPathToArray(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Target location |
Returns
Type | Description |
---|---|
System.String[] |
ReadBytes(String)
Return the bytes in a file.
由檔案傳回字節。
ReadBytes("C:/abc/efg/text.txt")
Declaration
public static byte[] ReadBytes(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path of file |
Returns
Type | Description |
---|---|
System.Byte[] |
ReadLines(String, Encoding)
Return the string array in a file.
由檔案傳回字串列。
ReadLines("C:/abc/efg/text.txt")
Declaration
public static string[] ReadLines(string path, Encoding format = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path of file |
System.Text.Encoding | format | Encoding format Default: Null = UTF8 |
Returns
Type | Description |
---|---|
System.String[] |
ReadText(String, Encoding)
Return the string in a file.
由檔案傳回字串。
ReadText("C:/abc/efg/text.txt")
Declaration
public static string ReadText(string path, Encoding format = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path of file |
System.Text.Encoding | format | Encoding format Default: Null = UTF8 |
Returns
Type | Description |
---|---|
System.String |
RealPath(String, FileLocation)
Return the full name of a path.
傳回路經的全名。
RealPath("C:/abc/efg/text.txt")
Declaration
public static string RealPath(string path, FileLocation sourcePath = FileLocation.AbsolutePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Target location |
FileLocation | sourcePath | Source path |
Returns
Type | Description |
---|---|
System.String |
WriteBytes(String, Byte[])
Write bytes to a file.
將字節寫入檔案。
WriteBytes("C:/abc/efg/text.txt", byteArray)
Declaration
public static void WriteBytes(string path, byte[] data)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path of file |
System.Byte[] | data | The data bytes |
WriteLines(String, List<String>)
Write string lines to a file.
將字串列寫入檔案。
WriteLines("C:/abc/efg/text.txt", new List<string>() { "abc", "efg", "123" })
Declaration
public static void WriteLines(string path, List<string> data)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path of file |
System.Collections.Generic.List<System.String> | data | The string list |
WriteLines(String, String[])
Write string lines to a file.
將字串列寫入檔案。
WriteLines("C:/abc/efg/text.txt", new string[]{ "abc", "efg", "123" })
Declaration
public static void WriteLines(string path, string[] data)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path of file |
System.String[] | data | The string array |
WriteText(String, String)
Write strings to a file.
將字串寫入檔案。
WriteText("C:/abc/efg/text.txt", "123")
Declaration
public static void WriteText(string path, string data)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path of file |
System.String | data | The string |