System.IO.Path.IsPathRooted C# (CSharp) Méthode

IsPathRooted() public static méthode

public static IsPathRooted ( string path ) : bool
path string
Résultat bool
        public static bool IsPathRooted(string path)
        {
            if (path != null)
            {
                PathInternal.CheckInvalidPathChars(path);

                int length = path.Length;
                if ((length >= 1 && PathInternal.IsDirectorySeparator(path[0])) || 
                    (length >= 2 && path[1] == VolumeSeparatorChar))
                    return true;
            }
            return false;
        }

Usage Example

Exemple #1
0
        // ExternalTokenHelperPath takes the configured path to a helper and expands it to
        // a full absolute path that can be executed. As of 0.5, the default token
        // helper is internal, to avoid problems running in dev mode (see GH-850 and
        // GH-783), so special assumptions of prepending "vault token-" no longer
        // apply.
        //
        // As an additional result, only absolute paths are now allowed. Looking in the
        // path or a current directory for an arbitrary executable could allow someone
        // to switch the expected binary for one further up the path (or in the current
        // directory), potentially opening up execution of an arbitrary binary.
        //~ func ExternalTokenHelperPath(path string) (string, error) {
        public static string ExternalTokenHelperPath(string path)
        {
            //~ if !filepath.IsAbs(path) {
            //~     var err error
            //~     path, err = filepath.Abs(path)
            //~     if err != nil {
            //~         return "", err
            //~     }
            //~ }
            if (!IOPath.IsPathRooted(path))
            {
                path = IOPath.GetFullPath(path);
            }

            //~ if _, err := os.Stat(path); err != nil {
            //~     return "", fmt.Errorf("unknown error getting the external helper path")
            //~ }
            //~
            //~ return path, nil
            if (File.Exists(path))
            {
                new FileInfo(path);
            }
            else if (Directory.Exists(path))
            {
                new DirectoryInfo(path);
            }
            else
            {
                throw new System.IO.FileNotFoundException();
            }

            return(path);
        }
All Usage Examples Of System.IO.Path::IsPathRooted