Created
December 10, 2014 00:54
-
-
Save liulixiang1988/2b3244f77593c098cfe9 to your computer and use it in GitHub Desktop.
C#-FileHelper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FileHelper | |
{ | |
/// <summary> | |
/// 返回文件扩展名 | |
/// </summary> | |
public static string GetExtension(string path) | |
{ | |
return Path.GetExtension(path); | |
} | |
/// <summary> | |
/// 返回文件名 | |
/// </summary> | |
public static string GetFileName(string path) | |
{ | |
return Path.GetFileName(path); | |
} | |
/// <summary> | |
/// 返回不含扩展名的文件名 | |
/// </summary> | |
public static string GetFileNameWithoutExtension(string path) | |
{ | |
return Path.GetFileNameWithoutExtension(path); | |
} | |
/// <summary> | |
/// 返回文件夹名 | |
/// </summary> | |
public static string GetDirectory(string path) | |
{ | |
return Path.GetDirectoryName(path); | |
} | |
/// <summary> | |
/// 打开文件 | |
/// </summary> | |
/// <param name="path">文件路径</param> | |
/// <param name="encoding">默认是utf-8</param> | |
/// <returns>返回StreamReader类型</returns> | |
public static StreamReader Open(string path, string encoding = "gb2312") | |
{ | |
return new StreamReader(path, Encoding.GetEncoding(encoding)); | |
} | |
public static string[] FileList(string path, string filterExtension = "*.DAT", | |
SearchOption searchOption = SearchOption.AllDirectories) | |
{ | |
return Directory.GetFiles(path, filterExtension, searchOption); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment