IsDirectorySeparator() public static method

public static IsDirectorySeparator ( char c ) : bool
c char
return bool
コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchData"/> class.
        /// </summary>
        /// <param name="fullPath">The full path.</param>
        /// <param name="userPath">The user path.</param>
        /// <param name="searchOptions">The search options.</param>
        public SearchData(String fullPath, String userPath, SearchOption searchOptions)
        {
            Contract.Requires(fullPath != null);
            Contract.Requires(searchOptions == SearchOption.AllDirectories || searchOptions == SearchOption.TopDirectoryOnly);

            if (PathHelperMethods.IsDirectorySeparator(fullPath[fullPath.Length - 1]))
            {
                this.fullPath = fullPath;
            }
            else
            {
                this.fullPath = fullPath + Path.DirectorySeparatorChar;
            }

            if (string.IsNullOrEmpty(userPath) || PathHelperMethods.IsDirectorySeparator(userPath[userPath.Length - 1]))
            {
                this.userPath = userPath;
            }
            else
            {
                this.userPath = userPath + Path.DirectorySeparatorChar;
            }

            this.searchOptions = searchOptions;
        }
コード例 #2
0
ファイル: ErrorHelper.cs プロジェクト: zdqszt/ipfilter
        static string GetDisplayablePath(string path, bool isInvalidPath)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return(path);
            }

            // Is it a fully qualified path?
            var isFullyQualified = false;

            if (path.Length < 2)
            {
                return(path);
            }

            if ((PathHelperMethods.IsDirectorySeparator(path[0]) && PathHelperMethods.IsDirectorySeparator(path[1])) || path[1] == Path.VolumeSeparatorChar)
            {
                isFullyQualified = true;
            }

            if (!isFullyQualified && !isInvalidPath)
            {
                return(path);
            }

            try
            {
                if (!isInvalidPath)
                {
                    new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new[] { path }).Demand();
                    return(path);
                }
            }
            catch (SecurityException) {}
            catch (ArgumentException)
            {
                // ? and * characters cause ArgumentException to be thrown from HasIllegalCharacters
                // inside FileIOPermission.AddPathList
            }
            catch (NotSupportedException)
            {
                // paths like "!Bogus\\dir:with/junk_.in it" can cause NotSupportedException to be thrown
                // from Security.Util.StringExpressionSet.CanonicalizePath when ':' is found in the path
                // beyond string index position 1.
            }

            if (PathHelperMethods.IsDirectorySeparator(path[path.Length - 1]))
            {
                throw new UnauthorizedAccessException($"No permission to directory name '{path}'");
            }

            return(Path.GetFileName(path));
        }
コード例 #3
0
        static String GetFullSearchString(String fullPath, String searchPattern)
        {
            Contract.Requires(fullPath != null);
            Contract.Requires(searchPattern != null);

            String tempStr = PathHelperMethods.InternalCombine(fullPath, searchPattern);

            // If path ends in a trailing slash (\), append a * or we'll get a "Cannot find the file specified" exception
            char lastChar = tempStr[tempStr.Length - 1];

            if (PathHelperMethods.IsDirectorySeparator(lastChar) || lastChar == Path.VolumeSeparatorChar)
            {
                tempStr = tempStr + '*';
            }

            return(tempStr);
        }
コード例 #4
0
        static String GetNormalizedSearchCriteria(String fullSearchString, String fullPathMod)
        {
            Contract.Requires(fullSearchString != null);
            Contract.Requires(fullPathMod != null);
            Contract.Requires(fullSearchString.Length >= fullPathMod.Length);

            String searchCriteria = null;
            char   lastChar       = fullPathMod[fullPathMod.Length - 1];

            if (PathHelperMethods.IsDirectorySeparator(lastChar))
            {
                // Can happen if the path is C:\temp, in which case GetDirectoryName would return C:\
                searchCriteria = fullSearchString.Substring(fullPathMod.Length);
            }
            else
            {
                Contract.Assert(fullSearchString.Length > fullPathMod.Length);
                searchCriteria = fullSearchString.Substring(fullPathMod.Length + 1);
            }
            return(searchCriteria);
        }