Windows-powershell / PowerShell-master /src /Microsoft.PowerShell.Commands.Management /commands /management /ConvertPathCommand.cs
| // Copyright (c) Microsoft Corporation. | |
| // Licensed under the MIT License. | |
| using System.Collections.ObjectModel; | |
| using System.Management.Automation; | |
| namespace Microsoft.PowerShell.Commands | |
| { | |
| /// <summary> | |
| /// A command to convert a drive qualified or provider qualified path to | |
| /// a provider internal path. | |
| /// </summary> | |
| [ | |
| ] | |
| [] | |
| public class ConvertPathCommand : CoreCommandBase | |
| { | |
| /// <summary> | |
| /// Gets or sets the path parameter to the command. | |
| /// </summary> | |
| [ | |
| ] | |
| public string[] Path | |
| { | |
| get | |
| { | |
| return _paths; | |
| } | |
| set | |
| { | |
| _paths = value; | |
| } | |
| } | |
| /// <summary> | |
| /// Gets or sets the literal path parameter to the command. | |
| /// </summary> | |
| [ | |
| ] | |
| [] | |
| public string[] LiteralPath | |
| { | |
| get | |
| { | |
| return _paths; | |
| } | |
| set | |
| { | |
| base.SuppressWildcardExpansion = true; | |
| _paths = value; | |
| } | |
| } | |
| /// <summary> | |
| /// Gets or sets the force property. | |
| /// </summary> | |
| [] | |
| public override SwitchParameter Force | |
| { | |
| get => base.Force; | |
| set => base.Force = value; | |
| } | |
| /// <summary> | |
| /// The path(s) to the item(s) to convert. | |
| /// </summary> | |
| private string[] _paths; | |
| /// <summary> | |
| /// Converts a drive qualified or provider qualified path to a provider | |
| /// internal path. | |
| /// </summary> | |
| protected override void ProcessRecord() | |
| { | |
| ProviderInfo provider = null; | |
| foreach (string path in Path) | |
| { | |
| try | |
| { | |
| Collection<string> results = | |
| SessionState.Path.GetResolvedProviderPathFromPSPath( | |
| path, | |
| CmdletProviderContext, | |
| out provider); | |
| WriteObject(results, true); | |
| } | |
| catch (PSNotSupportedException notSupported) | |
| { | |
| WriteError( | |
| new ErrorRecord( | |
| notSupported.ErrorRecord, | |
| notSupported)); | |
| continue; | |
| } | |
| catch (DriveNotFoundException driveNotFound) | |
| { | |
| WriteError( | |
| new ErrorRecord( | |
| driveNotFound.ErrorRecord, | |
| driveNotFound)); | |
| continue; | |
| } | |
| catch (ProviderNotFoundException providerNotFound) | |
| { | |
| WriteError( | |
| new ErrorRecord( | |
| providerNotFound.ErrorRecord, | |
| providerNotFound)); | |
| continue; | |
| } | |
| catch (ItemNotFoundException pathNotFound) | |
| { | |
| WriteError( | |
| new ErrorRecord( | |
| pathNotFound.ErrorRecord, | |
| pathNotFound)); | |
| continue; | |
| } | |
| } | |
| } | |
| } | |
| } | |