コード例 #1
0
        public static string GetFileName(string path)
        {
            Contract.Requires(!string.IsNullOrEmpty(path), "path musn't be null");

            if (path.EndsWith("/") || path.EndsWith("\\"))
            {
                return(string.Empty);
            }

            var nonRoot = PathInfo.Parse(path).FolderAndFiles;

            int strIndex;

            // resharper is wrong that you can transform this to a ternary operator.
            if ((strIndex = nonRoot.LastIndexOfAny(new[] { DirectorySeparatorChar, AltDirectorySeparatorChar })) != -1)
            {
                return(nonRoot.Substring(strIndex + 1));
            }

            return(nonRoot);
        }
コード例 #2
0
 public static PathInfo GetPathInfo(string path)
 {
     Contract.Requires(path != null);
     return(PathInfo.Parse(path));
 }