您的位置:首页 > 其它

分离出文件名 路径 后缀

2014-05-22 12:42 357 查看
/// <summary>
/// 分离出文件名 路径 后缀
/// </summary>
/// <param name="fullName">包括文件名和路径</param>
/// <returns>返回数组 0 path 1 filename 2 suffix </returns>
public string[] splitFileNamePathSuffix(string fullName)
{

string[] fileSplit = new string[3];
if (String.IsNullOrEmpty(fullName))
return null;

if (fullName.Contains("\\"))//windows mode
{
fileSplit[0] = fullName.Substring(0, fullName.LastIndexOf("\\")); //get path
fileSplit[1] = fullName.Substring(fullName.LastIndexOf("\\") + 1, (fullName.LastIndexOf(".") - fullName.LastIndexOf("\\") - 1)); //get file name
fileSplit[2] = fullName.Substring(fullName.LastIndexOf(".") + 1, (fullName.Length - fullName.LastIndexOf(".") - 1)); //get suffix
}
if (fullName.Contains("/"))//unix mode
{
fileSplit[0] = fullName.Substring(0, fullName.LastIndexOf("/")); //get path
fileSplit[1] = fullName.Substring(fullName.LastIndexOf("/") + 1, (fullName.LastIndexOf(".") - fullName.LastIndexOf("/") - 1)); //get file name
fileSplit[2] = fullName.Substring(fullName.LastIndexOf(".") + 1, (fullName.Length - fullName.LastIndexOf(".") - 1)); //get suffix

}
return fileSplit;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: