예제 #1
0
    //通过文件夹路径获取文件夹名
    public static bool GetNameByFolderPath(string folderPath, out string folderName)
    {
        folderName = "";
        if (folderPath == null || folderPath.Length == 0)
        {
            return(false);
        }
        char c = folderPath[folderPath.Length - 1];

        if (c == '\\' || c == '/')
        {
            folderPath = folderPath.Substring(0, folderPath.Length - 1);
        }

        int i     = folderPath.LastIndexOf("\\");
        int i1    = folderPath.LastIndexOf("/");
        int index = PreDefScrp.GetMax <int>(i, i1);

        if (index < 0)
        {
            Debug.Log("路径错误");
            return(false);
        }

        folderName = folderPath.Substring(index + 1);
        return(true);
    }
예제 #2
0
    //通过文件路径获取文件名,后缀
    public static bool GetNameByFilePath(string fullFilePath, out string fileName)
    {
        fileName = "";
        if (fullFilePath == null || fullFilePath.Length == 0)
        {
            return(false);
        }

        int i     = fullFilePath.LastIndexOf("\\");
        int i1    = fullFilePath.LastIndexOf("/");
        int index = PreDefScrp.GetMax <int>(i, i1);

        if (index < 0)
        {
            Debug.Log("路径错误");
            return(false);
        }

        fileName = fullFilePath.Substring(index + 1);//文件名包括后缀
        index    = fileName.LastIndexOf(".");
        if (index >= 0)
        {
            fileName = fileName.Substring(0, index);//去掉后缀
        }
        return(true);
    }