文件夹结构为:
--root
--root\source-code\
--root\powershell-scripts\我需要下面的\powershell-scripts文件夹中的方法来定位\source-code中的文件
function Test($param)
{
dir -Include ASourceCodeFile.txt -Recurse |
% { SomeMethod $_ $param }
}我遗漏了什么?
发布于 2019-11-18 17:41:16
有点晚了,但可能对某些人还是有帮助的:
目录结构:
MyRoot\script\scriptrunning.ps1配置:
MyRoot\config.xml从scriptrunning.ps1读取xml文件
[xml]$Config = Get-Content -path "${PSScriptRoot}\..\config\config.xml"发布于 2015-08-08 00:18:09
如果你在--root\powershell-scripts\中有一个脚本,并且你想在--root\source-code\中引用一些东西,或者说get-content,你可以这样做:
cd --root\powershell-scripts\
get-content '..\source-code\someFile.txt'..\引用包含\source-code\的父目录,然后您引用或拉入该目录中的文件或脚本。
发布于 2015-08-08 00:19:20
$PSScriptRoot自动变量包含当前脚本所在目录的路径。使用Split-Path查找其父文件夹(您的--root),使用Join-Path获取source-code文件夹的路径:
Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'source-code'PowerShell 3.0中引入了$PSScriptRoot
https://stackoverflow.com/questions/31882176
复制相似问题