我有一个可以像这样调用的自定义 cmdlet:
Get-Info ".\somefile.txt"
我的命令行开关代码如下所示:
[Parameter(Mandatory = true, Position = 0)]
public string FilePath { get; set; }
protected override void ProcessRecord()
{
using (var stream = File.Open(FilePath))
{
// Do work
}
}
但是,当我运行命令时,出现此错误:
Could not find file 'C:\Users\Philip\somefile.txt'
我没有从C:\Users\Philip
. 出于某种原因,我的 cmdlet 没有检测到工作目录,所以像这样的本地文件不起作用。在 C# 中,当提供本地“.\”文件路径时,推荐的检测正确文件路径的方法是什么?