Class PathHelpers
Various utilities that should be provided via System.IO.Path.
Inheritance
Namespace: Xamarin
Assembly: Xamarin.Helpers.dll
Syntax
public static class PathHelpers
Methods
| Improve this Doc View SourceFindProgramPath(String, IEnumerable<String>)
Locates the path of a program in the system, first searching in preferPaths
if specified, then falling back to the paths in PATH
environment variable. The first search
path to yield a match for programName
will be used to resolve the absolute
path of the program.
Declaration
public static string FindProgramPath(string programName, IEnumerable<string> preferPaths = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | programName | The name of the program to find. Do not specify a file extension. See remarks. |
System.Collections.Generic.IEnumerable<System.String> | preferPaths | Paths to search in preference over the |
Returns
Type | Description |
---|---|
System.String |
Remarks
The functionality is analogous to the which
command on Unix systems, and works on Windows
as well. On Windows, PATHEXT
is also respected. On Unix, files ending with .exe
will
also be returned if found - that is, one should not specify an extension at all in
programName
. Finally, programName
comparison is case
insensitive! For example, msbuild
may yield /path/to/MSBuild.exe
.
MakeRelativePath(String, String)
Makes path
relative to basePath
.
Declaration
public static string MakeRelativePath(string basePath, string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | basePath | |
System.String | path |
Returns
Type | Description |
---|---|
System.String |
NormalizePath(String)
Returns a path with / and \ directory separators normalized to System.IO.Path.DirectorySeparatorChar.
Declaration
public static string NormalizePath(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path |
Returns
Type | Description |
---|---|
System.String |
ResolveFullPath(String[])
A more exhaustive version of System.IO.Path.GetFullPath(System.String)
that additionally resolves symlinks via realpath
on Unix systems. The path
returned is also trimmed of any trailing directory separator characters.
Declaration
public static string ResolveFullPath(params string[] pathComponents)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | pathComponents | The path components to resolve to a full path. If multiple path compnents are specified, they are combined with System.IO.Path.Combine(System.String,System.String) before resolving. |
Returns
Type | Description |
---|---|
System.String | Returns |