到回购文件
Powershell的相对路径,我想指的文件,该文件是在同一回购的PowerShell脚本相对路径。到回购文件
我有以下目录结构。
repo/
├── files
│ └── scripts.sh
│
├── powershell_scripts
└── my_powershell.ps1
在
my_powershell.ps1
我要引用scripts.sh
。我试图在PowerShell脚本中使用$PSScriptRoot
,但它没有按照我想要的方式工作。
我想my_powershell.ps1
皮卡scripts.sh
与目录结构。
有谁知道如何做到这一点?
感谢
好了,在V3或更高,这是简单的。如果你想要的路径,“回购”的文件夹,你可以简单地指到当前文件夹的父如:
$Repo = Resolve-Path "$PSScriptRoot\.."
这将让你回购的文件夹对象。从那里你可以到达你的脚本文件夹。
,或者直接参考scripts.sh
文件,你可以这样做:
Resolve-Path "$PSScriptRoot\..\files\scripts.sh"
对不起,我没有得到这一点,可以指定完整的命令,我需要用它来指代'scripts.sh'成'my_powershell.ps1' – roy
我试过'$回购=解决路径“$ PSScriptRoot \ ..“''然后写主机$ Repo'其打印'C:\' – roy
是指'scripts.sh'成'my_powershell.ps1'怎么样?尝试'Get-Content“$ PSScriptRoot \ .. \ files \ scripts.sh”' – TheMadTechnician
我看你有没有PSV2列为标签。你真的会在版本2上运行这个吗? – TheMadTechnician
对PowerShell的V3.0运行它 – roy